Skip to content
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make ReadMe examples null-safe & fix errors.
  • Loading branch information
timbotimbo committed Dec 24, 2022
commit 89640b63e0d7fc98f778e607eba1005d51a57d0f
62 changes: 34 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,40 +434,41 @@ Unable to find a matching variant of project :unityLibrary:

```dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_unity_widget/flutter_unity_widget.dart';

void main() {
runApp(MaterialApp(
home: UnityDemoScreen()
));
runApp(
const MaterialApp(
home: UnityDemoScreen(),
),
);
}

class UnityDemoScreen extends StatefulWidget {

UnityDemoScreen({Key key}) : super(key: key);
const UnityDemoScreen({Key? key}) : super(key: key);

@override
_UnityDemoScreenState createState() => _UnityDemoScreenState();
State<UnityDemoScreen> createState() => _UnityDemoScreenState();
}

class _UnityDemoScreenState extends State<UnityDemoScreen>{
class _UnityDemoScreenState extends State<UnityDemoScreen> {
static final GlobalKey<ScaffoldState> _scaffoldKey =
GlobalKey<ScaffoldState>();
UnityWidgetController _unityWidgetController;
UnityWidgetController? _unityWidgetController;

@override
Widget build(BuildContext context) {

return Scaffold(
key: _scaffoldKey,
body: SafeArea(
bottom: false,
child: WillPopScope(
onWillPop: () {
onWillPop: () async {
// Pop the category page if Android back button is pressed.
return true;
},
child: Container(
color: colorYellow,
color: Colors.yellow,
child: UnityWidget(
onUnityCreated: onUnityCreated,
),
Expand All @@ -479,9 +480,10 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{

// Callback that connects the created controller to the unity controller
void onUnityCreated(controller) {
this._unityWidgetController = controller;
_unityWidgetController = controller;
}
}

```
<br />

Expand All @@ -491,17 +493,19 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
import 'package:flutter/material.dart';
import 'package:flutter_unity_widget/flutter_unity_widget.dart';

void main() => runApp(MyApp());
void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);

@override
_MyAppState createState() => _MyAppState();
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
static final GlobalKey<ScaffoldState> _scaffoldKey =
GlobalKey<ScaffoldState>();
UnityWidgetController _unityWidgetController;
UnityWidgetController? _unityWidgetController;
double _sliderValue = 0.0;

@override
Expand All @@ -526,10 +530,10 @@ class _MyAppState extends State<MyApp> {
child: Stack(
children: <Widget>[
UnityWidget(
onUnityCreated: onUnityCreated,
onUnityMessage: onUnityMessage,
onUnitySceneLoaded: onUnitySceneLoaded,
fullscreen: false,
onUnityCreated: onUnityCreated,
onUnityMessage: onUnityMessage,
onUnitySceneLoaded: onUnitySceneLoaded,
fullscreen: false,
),
Positioned(
bottom: 20,
Expand All @@ -539,8 +543,8 @@ class _MyAppState extends State<MyApp> {
elevation: 10,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 20),
const Padding(
padding: EdgeInsets.only(top: 20),
child: Text("Rotation speed:"),
),
Slider(
Expand All @@ -567,7 +571,7 @@ class _MyAppState extends State<MyApp> {

// Communcation from Flutter to Unity
void setRotationSpeed(String speed) {
_unityWidgetController.postMessage(
_unityWidgetController?.postMessage(
'Cube',
'SetRotationSpeed',
speed,
Expand All @@ -581,15 +585,17 @@ class _MyAppState extends State<MyApp> {

// Callback that connects the created controller to the unity controller
void onUnityCreated(controller) {
this._unityWidgetController = controller;
_unityWidgetController = controller;
}

// Communication from Unity when new scene is loaded to Flutter
void onUnitySceneLoaded(SceneLoaded sceneInfo) {
print('Received scene loaded from unity: ${sceneInfo.name}');
print('Received scene loaded from unity buildIndex: ${sceneInfo.buildIndex}');
void onUnitySceneLoaded(SceneLoaded? sceneInfo) {
if (sceneInfo != null) {
print('Received scene loaded from unity: ${sceneInfo.name}');
print(
'Received scene loaded from unity buildIndex: ${sceneInfo.buildIndex}');
}
}

}

```
Expand Down