@@ -434,40 +434,41 @@ Unable to find a matching variant of project :unityLibrary:
434
434
435
435
``` dart
436
436
import 'package:flutter/material.dart';
437
- import 'package:flutter/services.dart';
438
437
import 'package:flutter_unity_widget/flutter_unity_widget.dart';
439
438
440
439
void main() {
441
- runApp(MaterialApp(
442
- home: UnityDemoScreen()
443
- ));
440
+ runApp(
441
+ const MaterialApp(
442
+ home: UnityDemoScreen(),
443
+ ),
444
+ );
444
445
}
445
446
446
447
class UnityDemoScreen extends StatefulWidget {
447
-
448
- UnityDemoScreen({Key key}) : super(key: key);
448
+ const UnityDemoScreen({Key? key}) : super(key: key);
449
449
450
450
@override
451
- _UnityDemoScreenState createState() => _UnityDemoScreenState();
451
+ State<UnityDemoScreen> createState() => _UnityDemoScreenState();
452
452
}
453
453
454
- class _UnityDemoScreenState extends State<UnityDemoScreen>{
454
+ class _UnityDemoScreenState extends State<UnityDemoScreen> {
455
455
static final GlobalKey<ScaffoldState> _scaffoldKey =
456
456
GlobalKey<ScaffoldState>();
457
- UnityWidgetController _unityWidgetController;
457
+ UnityWidgetController? _unityWidgetController;
458
458
459
+ @override
459
460
Widget build(BuildContext context) {
460
-
461
461
return Scaffold(
462
462
key: _scaffoldKey,
463
463
body: SafeArea(
464
464
bottom: false,
465
465
child: WillPopScope(
466
- onWillPop: () {
466
+ onWillPop: () async {
467
467
// Pop the category page if Android back button is pressed.
468
+ return true;
468
469
},
469
470
child: Container(
470
- color: colorYellow ,
471
+ color: Colors.yellow ,
471
472
child: UnityWidget(
472
473
onUnityCreated: onUnityCreated,
473
474
),
@@ -479,9 +480,10 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
479
480
480
481
// Callback that connects the created controller to the unity controller
481
482
void onUnityCreated(controller) {
482
- this. _unityWidgetController = controller;
483
+ _unityWidgetController = controller;
483
484
}
484
485
}
486
+
485
487
```
486
488
<br />
487
489
@@ -491,17 +493,19 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
491
493
import 'package:flutter/material.dart';
492
494
import 'package:flutter_unity_widget/flutter_unity_widget.dart';
493
495
494
- void main() => runApp(MyApp());
496
+ void main() => runApp(const MyApp());
495
497
496
498
class MyApp extends StatefulWidget {
499
+ const MyApp({Key? key}) : super(key: key);
500
+
497
501
@override
498
- _MyAppState createState() => _MyAppState();
502
+ State<MyApp> createState() => _MyAppState();
499
503
}
500
504
501
505
class _MyAppState extends State<MyApp> {
502
506
static final GlobalKey<ScaffoldState> _scaffoldKey =
503
507
GlobalKey<ScaffoldState>();
504
- UnityWidgetController _unityWidgetController;
508
+ UnityWidgetController? _unityWidgetController;
505
509
double _sliderValue = 0.0;
506
510
507
511
@override
@@ -526,10 +530,10 @@ class _MyAppState extends State<MyApp> {
526
530
child: Stack(
527
531
children: <Widget>[
528
532
UnityWidget(
529
- onUnityCreated: onUnityCreated,
530
- onUnityMessage: onUnityMessage,
531
- onUnitySceneLoaded: onUnitySceneLoaded,
532
- fullscreen: false,
533
+ onUnityCreated: onUnityCreated,
534
+ onUnityMessage: onUnityMessage,
535
+ onUnitySceneLoaded: onUnitySceneLoaded,
536
+ fullscreen: false,
533
537
),
534
538
Positioned(
535
539
bottom: 20,
@@ -539,8 +543,8 @@ class _MyAppState extends State<MyApp> {
539
543
elevation: 10,
540
544
child: Column(
541
545
children: <Widget>[
542
- Padding(
543
- padding: const EdgeInsets.only(top: 20),
546
+ const Padding(
547
+ padding: EdgeInsets.only(top: 20),
544
548
child: Text("Rotation speed:"),
545
549
),
546
550
Slider(
@@ -567,7 +571,7 @@ class _MyAppState extends State<MyApp> {
567
571
568
572
// Communcation from Flutter to Unity
569
573
void setRotationSpeed(String speed) {
570
- _unityWidgetController.postMessage(
574
+ _unityWidgetController? .postMessage(
571
575
'Cube',
572
576
'SetRotationSpeed',
573
577
speed,
@@ -581,15 +585,17 @@ class _MyAppState extends State<MyApp> {
581
585
582
586
// Callback that connects the created controller to the unity controller
583
587
void onUnityCreated(controller) {
584
- this. _unityWidgetController = controller;
588
+ _unityWidgetController = controller;
585
589
}
586
590
587
591
// Communication from Unity when new scene is loaded to Flutter
588
- void onUnitySceneLoaded(SceneLoaded sceneInfo) {
589
- print('Received scene loaded from unity: ${sceneInfo.name}');
590
- print('Received scene loaded from unity buildIndex: ${sceneInfo.buildIndex}');
592
+ void onUnitySceneLoaded(SceneLoaded? sceneInfo) {
593
+ if (sceneInfo != null) {
594
+ print('Received scene loaded from unity: ${sceneInfo.name}');
595
+ print(
596
+ 'Received scene loaded from unity buildIndex: ${sceneInfo.buildIndex}');
597
+ }
591
598
}
592
-
593
599
}
594
600
595
601
```
0 commit comments