@@ -434,40 +434,41 @@ Unable to find a matching variant of project :unityLibrary:
434434
435435``` dart
436436import 'package:flutter/material.dart';
437- import 'package:flutter/services.dart';
438437import 'package:flutter_unity_widget/flutter_unity_widget.dart';
439438
440439void main() {
441- runApp(MaterialApp(
442- home: UnityDemoScreen()
443- ));
440+ runApp(
441+ const MaterialApp(
442+ home: UnityDemoScreen(),
443+ ),
444+ );
444445}
445446
446447class UnityDemoScreen extends StatefulWidget {
447-
448- UnityDemoScreen({Key key}) : super(key: key);
448+ const UnityDemoScreen({Key? key}) : super(key: key);
449449
450450 @override
451- _UnityDemoScreenState createState() => _UnityDemoScreenState();
451+ State<UnityDemoScreen> createState() => _UnityDemoScreenState();
452452}
453453
454- class _UnityDemoScreenState extends State<UnityDemoScreen>{
454+ class _UnityDemoScreenState extends State<UnityDemoScreen> {
455455 static final GlobalKey<ScaffoldState> _scaffoldKey =
456456 GlobalKey<ScaffoldState>();
457- UnityWidgetController _unityWidgetController;
457+ UnityWidgetController? _unityWidgetController;
458458
459+ @override
459460 Widget build(BuildContext context) {
460-
461461 return Scaffold(
462462 key: _scaffoldKey,
463463 body: SafeArea(
464464 bottom: false,
465465 child: WillPopScope(
466- onWillPop: () {
466+ onWillPop: () async {
467467 // Pop the category page if Android back button is pressed.
468+ return true;
468469 },
469470 child: Container(
470- color: colorYellow ,
471+ color: Colors.yellow ,
471472 child: UnityWidget(
472473 onUnityCreated: onUnityCreated,
473474 ),
@@ -479,9 +480,10 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
479480
480481 // Callback that connects the created controller to the unity controller
481482 void onUnityCreated(controller) {
482- this. _unityWidgetController = controller;
483+ _unityWidgetController = controller;
483484 }
484485}
486+
485487```
486488<br />
487489
@@ -491,17 +493,19 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
491493import 'package:flutter/material.dart';
492494import 'package:flutter_unity_widget/flutter_unity_widget.dart';
493495
494- void main() => runApp(MyApp());
496+ void main() => runApp(const MyApp());
495497
496498class MyApp extends StatefulWidget {
499+ const MyApp({Key? key}) : super(key: key);
500+
497501 @override
498- _MyAppState createState() => _MyAppState();
502+ State<MyApp> createState() => _MyAppState();
499503}
500504
501505class _MyAppState extends State<MyApp> {
502506 static final GlobalKey<ScaffoldState> _scaffoldKey =
503507 GlobalKey<ScaffoldState>();
504- UnityWidgetController _unityWidgetController;
508+ UnityWidgetController? _unityWidgetController;
505509 double _sliderValue = 0.0;
506510
507511 @override
@@ -526,10 +530,10 @@ class _MyAppState extends State<MyApp> {
526530 child: Stack(
527531 children: <Widget>[
528532 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,
533537 ),
534538 Positioned(
535539 bottom: 20,
@@ -539,8 +543,8 @@ class _MyAppState extends State<MyApp> {
539543 elevation: 10,
540544 child: Column(
541545 children: <Widget>[
542- Padding(
543- padding: const EdgeInsets.only(top: 20),
546+ const Padding(
547+ padding: EdgeInsets.only(top: 20),
544548 child: Text("Rotation speed:"),
545549 ),
546550 Slider(
@@ -567,7 +571,7 @@ class _MyAppState extends State<MyApp> {
567571
568572 // Communcation from Flutter to Unity
569573 void setRotationSpeed(String speed) {
570- _unityWidgetController.postMessage(
574+ _unityWidgetController? .postMessage(
571575 'Cube',
572576 'SetRotationSpeed',
573577 speed,
@@ -581,15 +585,17 @@ class _MyAppState extends State<MyApp> {
581585
582586 // Callback that connects the created controller to the unity controller
583587 void onUnityCreated(controller) {
584- this. _unityWidgetController = controller;
588+ _unityWidgetController = controller;
585589 }
586590
587591 // 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+ }
591598 }
592-
593599}
594600
595601```
0 commit comments