@@ -479,40 +479,41 @@ Unable to find a matching variant of project :unityLibrary:
479479
480480``` dart
481481import 'package:flutter/material.dart';
482- import 'package:flutter/services.dart';
483482import 'package:flutter_unity_widget/flutter_unity_widget.dart';
484483
485484void main() {
486- runApp(MaterialApp(
487- home: UnityDemoScreen()
488- ));
485+ runApp(
486+ const MaterialApp(
487+ home: UnityDemoScreen(),
488+ ),
489+ );
489490}
490491
491492class UnityDemoScreen extends StatefulWidget {
492-
493- UnityDemoScreen({Key key}) : super(key: key);
493+ const UnityDemoScreen({Key? key}) : super(key: key);
494494
495495 @override
496- _UnityDemoScreenState createState() => _UnityDemoScreenState();
496+ State<UnityDemoScreen> createState() => _UnityDemoScreenState();
497497}
498498
499- class _UnityDemoScreenState extends State<UnityDemoScreen>{
499+ class _UnityDemoScreenState extends State<UnityDemoScreen> {
500500 static final GlobalKey<ScaffoldState> _scaffoldKey =
501501 GlobalKey<ScaffoldState>();
502- UnityWidgetController _unityWidgetController;
502+ UnityWidgetController? _unityWidgetController;
503503
504+ @override
504505 Widget build(BuildContext context) {
505-
506506 return Scaffold(
507507 key: _scaffoldKey,
508508 body: SafeArea(
509509 bottom: false,
510510 child: WillPopScope(
511- onWillPop: () {
511+ onWillPop: () async {
512512 // Pop the category page if Android back button is pressed.
513+ return true;
513514 },
514515 child: Container(
515- color: colorYellow ,
516+ color: Colors.yellow ,
516517 child: UnityWidget(
517518 onUnityCreated: onUnityCreated,
518519 ),
@@ -524,9 +525,10 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
524525
525526 // Callback that connects the created controller to the unity controller
526527 void onUnityCreated(controller) {
527- this. _unityWidgetController = controller;
528+ _unityWidgetController = controller;
528529 }
529530}
531+
530532```
531533<br />
532534
@@ -536,17 +538,19 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
536538import 'package:flutter/material.dart';
537539import 'package:flutter_unity_widget/flutter_unity_widget.dart';
538540
539- void main() => runApp(MyApp());
541+ void main() => runApp(const MyApp());
540542
541543class MyApp extends StatefulWidget {
544+ const MyApp({Key? key}) : super(key: key);
545+
542546 @override
543- _MyAppState createState() => _MyAppState();
547+ State<MyApp> createState() => _MyAppState();
544548}
545549
546550class _MyAppState extends State<MyApp> {
547551 static final GlobalKey<ScaffoldState> _scaffoldKey =
548552 GlobalKey<ScaffoldState>();
549- UnityWidgetController _unityWidgetController;
553+ UnityWidgetController? _unityWidgetController;
550554 double _sliderValue = 0.0;
551555
552556 @override
@@ -571,10 +575,10 @@ class _MyAppState extends State<MyApp> {
571575 child: Stack(
572576 children: <Widget>[
573577 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,
578582 ),
579583 Positioned(
580584 bottom: 20,
@@ -584,8 +588,8 @@ class _MyAppState extends State<MyApp> {
584588 elevation: 10,
585589 child: Column(
586590 children: <Widget>[
587- Padding(
588- padding: const EdgeInsets.only(top: 20),
591+ const Padding(
592+ padding: EdgeInsets.only(top: 20),
589593 child: Text("Rotation speed:"),
590594 ),
591595 Slider(
@@ -612,7 +616,7 @@ class _MyAppState extends State<MyApp> {
612616
613617 // Communcation from Flutter to Unity
614618 void setRotationSpeed(String speed) {
615- _unityWidgetController.postMessage(
619+ _unityWidgetController? .postMessage(
616620 'Cube',
617621 'SetRotationSpeed',
618622 speed,
@@ -626,15 +630,17 @@ class _MyAppState extends State<MyApp> {
626630
627631 // Callback that connects the created controller to the unity controller
628632 void onUnityCreated(controller) {
629- this. _unityWidgetController = controller;
633+ _unityWidgetController = controller;
630634 }
631635
632636 // 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+ }
636643 }
637-
638644}
639645
640646```
0 commit comments