@@ -479,40 +479,41 @@ Unable to find a matching variant of project :unityLibrary:
479
479
480
480
``` dart
481
481
import 'package:flutter/material.dart';
482
- import 'package:flutter/services.dart';
483
482
import 'package:flutter_unity_widget/flutter_unity_widget.dart';
484
483
485
484
void main() {
486
- runApp(MaterialApp(
487
- home: UnityDemoScreen()
488
- ));
485
+ runApp(
486
+ const MaterialApp(
487
+ home: UnityDemoScreen(),
488
+ ),
489
+ );
489
490
}
490
491
491
492
class UnityDemoScreen extends StatefulWidget {
492
-
493
- UnityDemoScreen({Key key}) : super(key: key);
493
+ const UnityDemoScreen({Key? key}) : super(key: key);
494
494
495
495
@override
496
- _UnityDemoScreenState createState() => _UnityDemoScreenState();
496
+ State<UnityDemoScreen> createState() => _UnityDemoScreenState();
497
497
}
498
498
499
- class _UnityDemoScreenState extends State<UnityDemoScreen>{
499
+ class _UnityDemoScreenState extends State<UnityDemoScreen> {
500
500
static final GlobalKey<ScaffoldState> _scaffoldKey =
501
501
GlobalKey<ScaffoldState>();
502
- UnityWidgetController _unityWidgetController;
502
+ UnityWidgetController? _unityWidgetController;
503
503
504
+ @override
504
505
Widget build(BuildContext context) {
505
-
506
506
return Scaffold(
507
507
key: _scaffoldKey,
508
508
body: SafeArea(
509
509
bottom: false,
510
510
child: WillPopScope(
511
- onWillPop: () {
511
+ onWillPop: () async {
512
512
// Pop the category page if Android back button is pressed.
513
+ return true;
513
514
},
514
515
child: Container(
515
- color: colorYellow ,
516
+ color: Colors.yellow ,
516
517
child: UnityWidget(
517
518
onUnityCreated: onUnityCreated,
518
519
),
@@ -524,9 +525,10 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
524
525
525
526
// Callback that connects the created controller to the unity controller
526
527
void onUnityCreated(controller) {
527
- this. _unityWidgetController = controller;
528
+ _unityWidgetController = controller;
528
529
}
529
530
}
531
+
530
532
```
531
533
<br />
532
534
@@ -536,17 +538,19 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
536
538
import 'package:flutter/material.dart';
537
539
import 'package:flutter_unity_widget/flutter_unity_widget.dart';
538
540
539
- void main() => runApp(MyApp());
541
+ void main() => runApp(const MyApp());
540
542
541
543
class MyApp extends StatefulWidget {
544
+ const MyApp({Key? key}) : super(key: key);
545
+
542
546
@override
543
- _MyAppState createState() => _MyAppState();
547
+ State<MyApp> createState() => _MyAppState();
544
548
}
545
549
546
550
class _MyAppState extends State<MyApp> {
547
551
static final GlobalKey<ScaffoldState> _scaffoldKey =
548
552
GlobalKey<ScaffoldState>();
549
- UnityWidgetController _unityWidgetController;
553
+ UnityWidgetController? _unityWidgetController;
550
554
double _sliderValue = 0.0;
551
555
552
556
@override
@@ -571,10 +575,10 @@ class _MyAppState extends State<MyApp> {
571
575
child: Stack(
572
576
children: <Widget>[
573
577
UnityWidget(
574
- onUnityCreated: onUnityCreated,
575
- onUnityMessage: onUnityMessage,
576
- onUnitySceneLoaded: onUnitySceneLoaded,
577
- fullscreen: false,
578
+ onUnityCreated: onUnityCreated,
579
+ onUnityMessage: onUnityMessage,
580
+ onUnitySceneLoaded: onUnitySceneLoaded,
581
+ fullscreen: false,
578
582
),
579
583
Positioned(
580
584
bottom: 20,
@@ -584,8 +588,8 @@ class _MyAppState extends State<MyApp> {
584
588
elevation: 10,
585
589
child: Column(
586
590
children: <Widget>[
587
- Padding(
588
- padding: const EdgeInsets.only(top: 20),
591
+ const Padding(
592
+ padding: EdgeInsets.only(top: 20),
589
593
child: Text("Rotation speed:"),
590
594
),
591
595
Slider(
@@ -612,7 +616,7 @@ class _MyAppState extends State<MyApp> {
612
616
613
617
// Communcation from Flutter to Unity
614
618
void setRotationSpeed(String speed) {
615
- _unityWidgetController.postMessage(
619
+ _unityWidgetController? .postMessage(
616
620
'Cube',
617
621
'SetRotationSpeed',
618
622
speed,
@@ -626,15 +630,17 @@ class _MyAppState extends State<MyApp> {
626
630
627
631
// Callback that connects the created controller to the unity controller
628
632
void onUnityCreated(controller) {
629
- this. _unityWidgetController = controller;
633
+ _unityWidgetController = controller;
630
634
}
631
635
632
636
// Communication from Unity when new scene is loaded to Flutter
633
- void onUnitySceneLoaded(SceneLoaded sceneInfo) {
634
- print('Received scene loaded from unity: ${sceneInfo.name}');
635
- print('Received scene loaded from unity buildIndex: ${sceneInfo.buildIndex}');
637
+ void onUnitySceneLoaded(SceneLoaded? sceneInfo) {
638
+ if (sceneInfo != null) {
639
+ print('Received scene loaded from unity: ${sceneInfo.name}');
640
+ print(
641
+ 'Received scene loaded from unity buildIndex: ${sceneInfo.buildIndex}');
642
+ }
636
643
}
637
-
638
644
}
639
645
640
646
```
0 commit comments