import 'package:flutter/material.dart'; import 'package:flutter_unity_widget/flutter_unity_widget.dart'; class WithARkitScreen extends StatefulWidget { @override _WithARkitScreenState createState() => _WithARkitScreenState(); } class _WithARkitScreenState extends State { static final GlobalKey _scaffoldKey = GlobalKey(); UnityWidgetController _unityWidgetController; double _sliderValue = 0.0; @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( key: _scaffoldKey, appBar: AppBar( title: const Text('Unity Flutter Demo'), ), body: Card( margin: const EdgeInsets.all(8), clipBehavior: Clip.antiAlias, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(20.0), ), child: Stack( children: [ UnityWidget( onUnityViewCreated: onUnityCreated, isARScene: false, onUnityMessage: onUnityMessage, ), Positioned( bottom: 20, left: 20, right: 20, child: Card( elevation: 10, child: Column( children: [ Padding( padding: const EdgeInsets.only(top: 20), child: Text("Rotation speed:"), ), Slider( onChanged: (value) { setState(() { _sliderValue = value; }); setRotationSpeed(value.toString()); }, value: _sliderValue, min: 0, max: 20, ), ], ), ), ), ], ), ), ), ); } void setRotationSpeed(String speed) { _unityWidgetController.postMessage( 'Cube', 'SetRotationSpeed', speed, ); } void onUnityMessage(controller, message) { print('Received message from unity: ${message.toString()}'); } // Callback that connects the created controller to the unity controller void onUnityCreated(controller) { this._unityWidgetController = controller; } }