@@ -523,40 +523,41 @@ Unable to find a matching variant of project :unityLibrary:
523523
524524``` dart
525525import 'package:flutter/material.dart';
526- import 'package:flutter/services.dart';
527526import 'package:flutter_unity_widget/flutter_unity_widget.dart';
528527
529528void main() {
530- runApp(MaterialApp(
531- home: UnityDemoScreen()
532- ));
529+ runApp(
530+ const MaterialApp(
531+ home: UnityDemoScreen(),
532+ ),
533+ );
533534}
534535
535536class UnityDemoScreen extends StatefulWidget {
536-
537- UnityDemoScreen({Key key}) : super(key: key);
537+ const UnityDemoScreen({Key? key}) : super(key: key);
538538
539539 @override
540- _UnityDemoScreenState createState() => _UnityDemoScreenState();
540+ State<UnityDemoScreen> createState() => _UnityDemoScreenState();
541541}
542542
543- class _UnityDemoScreenState extends State<UnityDemoScreen>{
543+ class _UnityDemoScreenState extends State<UnityDemoScreen> {
544544 static final GlobalKey<ScaffoldState> _scaffoldKey =
545545 GlobalKey<ScaffoldState>();
546- UnityWidgetController _unityWidgetController;
546+ UnityWidgetController? _unityWidgetController;
547547
548+ @override
548549 Widget build(BuildContext context) {
549-
550550 return Scaffold(
551551 key: _scaffoldKey,
552552 body: SafeArea(
553553 bottom: false,
554554 child: WillPopScope(
555- onWillPop: () {
555+ onWillPop: () async {
556556 // Pop the category page if Android back button is pressed.
557+ return true;
557558 },
558559 child: Container(
559- color: colorYellow ,
560+ color: Colors.yellow ,
560561 child: UnityWidget(
561562 onUnityCreated: onUnityCreated,
562563 ),
@@ -568,9 +569,10 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
568569
569570 // Callback that connects the created controller to the unity controller
570571 void onUnityCreated(controller) {
571- this. _unityWidgetController = controller;
572+ _unityWidgetController = controller;
572573 }
573574}
575+
574576```
575577<br />
576578
@@ -580,17 +582,19 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
580582import 'package:flutter/material.dart';
581583import 'package:flutter_unity_widget/flutter_unity_widget.dart';
582584
583- void main() => runApp(MyApp());
585+ void main() => runApp(const MyApp());
584586
585587class MyApp extends StatefulWidget {
588+ const MyApp({Key? key}) : super(key: key);
589+
586590 @override
587- _MyAppState createState() => _MyAppState();
591+ State<MyApp> createState() => _MyAppState();
588592}
589593
590594class _MyAppState extends State<MyApp> {
591595 static final GlobalKey<ScaffoldState> _scaffoldKey =
592596 GlobalKey<ScaffoldState>();
593- UnityWidgetController _unityWidgetController;
597+ UnityWidgetController? _unityWidgetController;
594598 double _sliderValue = 0.0;
595599
596600 @override
@@ -615,10 +619,10 @@ class _MyAppState extends State<MyApp> {
615619 child: Stack(
616620 children: <Widget>[
617621 UnityWidget(
618- onUnityCreated: onUnityCreated,
619- onUnityMessage: onUnityMessage,
620- onUnitySceneLoaded: onUnitySceneLoaded,
621- fullscreen: false,
622+ onUnityCreated: onUnityCreated,
623+ onUnityMessage: onUnityMessage,
624+ onUnitySceneLoaded: onUnitySceneLoaded,
625+ fullscreen: false,
622626 ),
623627 Positioned(
624628 bottom: 20,
@@ -628,8 +632,8 @@ class _MyAppState extends State<MyApp> {
628632 elevation: 10,
629633 child: Column(
630634 children: <Widget>[
631- Padding(
632- padding: const EdgeInsets.only(top: 20),
635+ const Padding(
636+ padding: EdgeInsets.only(top: 20),
633637 child: Text("Rotation speed:"),
634638 ),
635639 Slider(
@@ -656,7 +660,7 @@ class _MyAppState extends State<MyApp> {
656660
657661 // Communcation from Flutter to Unity
658662 void setRotationSpeed(String speed) {
659- _unityWidgetController.postMessage(
663+ _unityWidgetController? .postMessage(
660664 'Cube',
661665 'SetRotationSpeed',
662666 speed,
@@ -670,15 +674,17 @@ class _MyAppState extends State<MyApp> {
670674
671675 // Callback that connects the created controller to the unity controller
672676 void onUnityCreated(controller) {
673- this. _unityWidgetController = controller;
677+ _unityWidgetController = controller;
674678 }
675679
676680 // Communication from Unity when new scene is loaded to Flutter
677- void onUnitySceneLoaded(SceneLoaded sceneInfo) {
678- print('Received scene loaded from unity: ${sceneInfo.name}');
679- print('Received scene loaded from unity buildIndex: ${sceneInfo.buildIndex}');
681+ void onUnitySceneLoaded(SceneLoaded? sceneInfo) {
682+ if (sceneInfo != null) {
683+ print('Received scene loaded from unity: ${sceneInfo.name}');
684+ print(
685+ 'Received scene loaded from unity buildIndex: ${sceneInfo.buildIndex}');
686+ }
680687 }
681-
682688}
683689
684690```
0 commit comments