Compare commits
No commits in common. 'e5f1398bc3c2965187a2b47e4dc8adac598f28ae' and 'cacb3d6e75d39ee3dbccd725088557b5fa9741d5' have entirely different histories.
e5f1398bc3
...
cacb3d6e75
@ -1,37 +1,63 @@ |
|||||||
import 'package:flutter/material.dart'; |
import 'package:flutter/material.dart'; |
||||||
import 'package:flutter_cocos_view_example/screens/no_interaction_screen.dart'; |
import 'dart:async'; |
||||||
import 'package:flutter_cocos_view_example/screens/orientation_screen.dart'; |
|
||||||
|
|
||||||
import 'menu_screen.dart'; |
import 'package:flutter/services.dart'; |
||||||
import 'screens/api_screen.dart'; |
import 'package:flutter_cocos_view/flutter_cocos_view.dart'; |
||||||
import 'screens/loader_screen.dart'; |
|
||||||
import 'screens/simple_screen.dart'; |
|
||||||
|
|
||||||
void main() { |
void main() { |
||||||
runApp(const MyApp()); |
runApp(const MyApp()); |
||||||
} |
} |
||||||
|
|
||||||
class MyApp extends StatelessWidget { |
class MyApp extends StatefulWidget { |
||||||
const MyApp({Key? key}) : super(key: key); |
const MyApp({super.key}); |
||||||
|
|
||||||
|
@override |
||||||
|
State<MyApp> createState() => _MyAppState(); |
||||||
|
} |
||||||
|
|
||||||
|
class _MyAppState extends State<MyApp> { |
||||||
|
String _platformVersion = 'Unknown'; |
||||||
|
final _flutterCocosViewPlugin = FlutterCocosView(); |
||||||
|
|
||||||
|
@override |
||||||
|
void initState() { |
||||||
|
super.initState(); |
||||||
|
initPlatformState(); |
||||||
|
} |
||||||
|
|
||||||
|
// Platform messages are asynchronous, so we initialize in an async method. |
||||||
|
Future<void> initPlatformState() async { |
||||||
|
String platformVersion; |
||||||
|
// Platform messages may fail, so we use a try/catch PlatformException. |
||||||
|
// We also handle the message potentially returning null. |
||||||
|
try { |
||||||
|
platformVersion = |
||||||
|
await _flutterCocosViewPlugin.getPlatformVersion() ?? 'Unknown platform version'; |
||||||
|
} on PlatformException { |
||||||
|
platformVersion = 'Failed to get platform version.'; |
||||||
|
} |
||||||
|
|
||||||
|
// If the widget was removed from the tree while the asynchronous platform |
||||||
|
// message was in flight, we want to discard the reply rather than calling |
||||||
|
// setState to update our non-existent appearance. |
||||||
|
if (!mounted) return; |
||||||
|
|
||||||
|
setState(() { |
||||||
|
_platformVersion = platformVersion; |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
// This widget is the root of your application. |
|
||||||
@override |
@override |
||||||
Widget build(BuildContext context) { |
Widget build(BuildContext context) { |
||||||
return MaterialApp( |
return MaterialApp( |
||||||
title: 'Flutter Cocos Demo', |
home: Scaffold( |
||||||
theme: ThemeData( |
appBar: AppBar( |
||||||
primarySwatch: Colors.blue, |
title: const Text('Plugin example app'), |
||||||
visualDensity: VisualDensity.adaptivePlatformDensity, |
), |
||||||
|
body: Center( |
||||||
|
child: Text('Running on: $_platformVersion\n'), |
||||||
|
), |
||||||
), |
), |
||||||
initialRoute: '/', |
|
||||||
routes: { |
|
||||||
'/': (context) => const MenuScreen(), |
|
||||||
'/simple': (context) => const SimpleScreen(), |
|
||||||
'/loader': (context) => const LoaderScreen(), |
|
||||||
'/orientation': (context) => const OrientationScreen(), |
|
||||||
'/api': (context) => const ApiScreen(), |
|
||||||
'/none': (context) => const NoInteractionScreen(), |
|
||||||
}, |
|
||||||
); |
); |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,76 +0,0 @@ |
|||||||
import 'package:flutter/material.dart'; |
|
||||||
|
|
||||||
class MenuScreen extends StatefulWidget { |
|
||||||
const MenuScreen({Key? key}) : super(key: key); |
|
||||||
|
|
||||||
@override |
|
||||||
State<MenuScreen> createState() => _MenuScreenState(); |
|
||||||
} |
|
||||||
|
|
||||||
class _MenuScreenState extends State<MenuScreen> { |
|
||||||
List<_MenuListItem> menus = [ |
|
||||||
_MenuListItem( |
|
||||||
description: 'Simple demonstration of cocos flutter library', |
|
||||||
route: '/simple', |
|
||||||
title: 'Simple Cocos Demo', |
|
||||||
), |
|
||||||
_MenuListItem( |
|
||||||
description: 'No interaction of cocos flutter library', |
|
||||||
route: '/none', |
|
||||||
title: 'No Interaction Cocos Demo', |
|
||||||
), |
|
||||||
_MenuListItem( |
|
||||||
description: 'Cocos load and unload cocos demo', |
|
||||||
route: '/loader', |
|
||||||
title: 'Safe mode Demo', |
|
||||||
), |
|
||||||
_MenuListItem( |
|
||||||
description: |
|
||||||
'This example shows various native API exposed by the library', |
|
||||||
route: '/api', |
|
||||||
title: 'Native exposed API demo', |
|
||||||
), |
|
||||||
_MenuListItem( |
|
||||||
title: 'Test Orientation', |
|
||||||
route: '/orientation', |
|
||||||
description: 'test orientation change', |
|
||||||
), |
|
||||||
]; |
|
||||||
|
|
||||||
@override |
|
||||||
Widget build(BuildContext context) { |
|
||||||
return Scaffold( |
|
||||||
appBar: AppBar( |
|
||||||
title: const Text('Menu List'), |
|
||||||
), |
|
||||||
body: Center( |
|
||||||
child: ListView.builder( |
|
||||||
itemCount: menus.length, |
|
||||||
itemBuilder: (BuildContext context, int i) { |
|
||||||
return ListTile( |
|
||||||
title: Text(menus[i].title), |
|
||||||
subtitle: Text(menus[i].description), |
|
||||||
onTap: () { |
|
||||||
Navigator.of(context).pushNamed( |
|
||||||
menus[i].route, |
|
||||||
); |
|
||||||
}, |
|
||||||
); |
|
||||||
}, |
|
||||||
), |
|
||||||
), |
|
||||||
); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
class _MenuListItem { |
|
||||||
final String title; |
|
||||||
final String description; |
|
||||||
final String route; |
|
||||||
|
|
||||||
_MenuListItem({ |
|
||||||
required this.title, |
|
||||||
required this.description, |
|
||||||
required this.route, |
|
||||||
}); |
|
||||||
} |
|
@ -1,168 +0,0 @@ |
|||||||
// ignore_for_file: avoid_print |
|
||||||
|
|
||||||
import 'package:flutter/material.dart'; |
|
||||||
import "package:flutter_cocos_view/flutter_cocos_view.dart"; |
|
||||||
import 'package:pointer_interceptor/pointer_interceptor.dart'; |
|
||||||
|
|
||||||
class ApiScreen extends StatefulWidget { |
|
||||||
const ApiScreen({Key? key}) : super(key: key); |
|
||||||
|
|
||||||
@override |
|
||||||
State<ApiScreen> createState() => _ApiScreenState(); |
|
||||||
} |
|
||||||
|
|
||||||
class _ApiScreenState extends State<ApiScreen> { |
|
||||||
CocosWidgetController? _cocosWidgetController; |
|
||||||
double _sliderValue = 0.0; |
|
||||||
|
|
||||||
@override |
|
||||||
void initState() { |
|
||||||
super.initState(); |
|
||||||
} |
|
||||||
|
|
||||||
@override |
|
||||||
void dispose() { |
|
||||||
_cocosWidgetController?.dispose(); |
|
||||||
super.dispose(); |
|
||||||
} |
|
||||||
|
|
||||||
@override |
|
||||||
Widget build(BuildContext context) { |
|
||||||
return Scaffold( |
|
||||||
appBar: AppBar( |
|
||||||
title: const Text('API Screen'), |
|
||||||
), |
|
||||||
body: Card( |
|
||||||
margin: const EdgeInsets.all(8), |
|
||||||
clipBehavior: Clip.antiAlias, |
|
||||||
shape: RoundedRectangleBorder( |
|
||||||
borderRadius: BorderRadius.circular(20.0), |
|
||||||
), |
|
||||||
child: Stack( |
|
||||||
children: [ |
|
||||||
CocosWidget( |
|
||||||
onCocosCreated: onCocosCreated, |
|
||||||
onCocosMessage: onCocosMessage, |
|
||||||
onCocosSceneLoaded: onCocosSceneLoaded, |
|
||||||
fullscreen: false, |
|
||||||
useAndroidViewSurface: false, |
|
||||||
), |
|
||||||
Positioned( |
|
||||||
bottom: 20, |
|
||||||
left: 20, |
|
||||||
right: 20, |
|
||||||
child: PointerInterceptor( |
|
||||||
child: Card( |
|
||||||
elevation: 10, |
|
||||||
child: Column( |
|
||||||
mainAxisSize: MainAxisSize.min, |
|
||||||
children: <Widget>[ |
|
||||||
const Padding( |
|
||||||
padding: EdgeInsets.only(top: 20), |
|
||||||
child: Text("Rotation speed:"), |
|
||||||
), |
|
||||||
Slider( |
|
||||||
onChanged: (value) { |
|
||||||
setState(() { |
|
||||||
_sliderValue = value; |
|
||||||
}); |
|
||||||
setRotationSpeed(value.toString()); |
|
||||||
}, |
|
||||||
value: _sliderValue, |
|
||||||
min: 0, |
|
||||||
max: 20, |
|
||||||
), |
|
||||||
FittedBox( |
|
||||||
child: Row( |
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
||||||
children: [ |
|
||||||
MaterialButton( |
|
||||||
onPressed: () { |
|
||||||
_cocosWidgetController?.quit(); |
|
||||||
}, |
|
||||||
child: const Text("Quit"), |
|
||||||
), |
|
||||||
MaterialButton( |
|
||||||
onPressed: () { |
|
||||||
_cocosWidgetController?.create(); |
|
||||||
}, |
|
||||||
child: const Text("Create"), |
|
||||||
), |
|
||||||
MaterialButton( |
|
||||||
onPressed: () { |
|
||||||
_cocosWidgetController?.pause(); |
|
||||||
}, |
|
||||||
child: const Text("Pause"), |
|
||||||
), |
|
||||||
MaterialButton( |
|
||||||
onPressed: () { |
|
||||||
_cocosWidgetController?.resume(); |
|
||||||
}, |
|
||||||
child: const Text("Resume"), |
|
||||||
), |
|
||||||
], |
|
||||||
), |
|
||||||
), |
|
||||||
FittedBox( |
|
||||||
child: Row( |
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
||||||
children: [ |
|
||||||
MaterialButton( |
|
||||||
onPressed: () async { |
|
||||||
await _cocosWidgetController |
|
||||||
?.openInNativeProcess(); |
|
||||||
}, |
|
||||||
child: const Text("Open Native"), |
|
||||||
), |
|
||||||
MaterialButton( |
|
||||||
onPressed: () { |
|
||||||
_cocosWidgetController?.unload(); |
|
||||||
}, |
|
||||||
child: const Text("Unload"), |
|
||||||
), |
|
||||||
MaterialButton( |
|
||||||
onPressed: () { |
|
||||||
_cocosWidgetController?.quit(); |
|
||||||
}, |
|
||||||
child: const Text("Silent Quit"), |
|
||||||
), |
|
||||||
], |
|
||||||
), |
|
||||||
), |
|
||||||
], |
|
||||||
), |
|
||||||
), |
|
||||||
), |
|
||||||
), |
|
||||||
], |
|
||||||
), |
|
||||||
), |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
void setRotationSpeed(String speed) { |
|
||||||
_cocosWidgetController?.postMessage( |
|
||||||
'Cube', |
|
||||||
'SetRotationSpeed', |
|
||||||
speed, |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
void onCocosMessage(message) { |
|
||||||
print('Received message from cocos: ${message.toString()}'); |
|
||||||
} |
|
||||||
|
|
||||||
void onCocosSceneLoaded(SceneLoaded? scene) { |
|
||||||
if (scene != null) { |
|
||||||
print('Received scene loaded from cocos: ${scene.name}'); |
|
||||||
print('Received scene loaded from cocos buildIndex: ${scene.buildIndex}'); |
|
||||||
} else { |
|
||||||
print('Received scene loaded from cocos: null'); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Callback that connects the created controller to the cocos controller |
|
||||||
void onCocosCreated(controller) { |
|
||||||
_cocosWidgetController = controller; |
|
||||||
} |
|
||||||
} |
|
@ -1,93 +0,0 @@ |
|||||||
// ignore_for_file: avoid_print |
|
||||||
|
|
||||||
import 'package:flutter/material.dart'; |
|
||||||
import 'package:flutter_cocos_view/flutter_cocos_view.dart'; |
|
||||||
import 'package:pointer_interceptor/pointer_interceptor.dart'; |
|
||||||
|
|
||||||
class LoaderScreen extends StatefulWidget { |
|
||||||
const LoaderScreen({Key? key}) : super(key: key); |
|
||||||
|
|
||||||
@override |
|
||||||
State<LoaderScreen> createState() => _LoaderScreenState(); |
|
||||||
} |
|
||||||
|
|
||||||
class _LoaderScreenState extends State<LoaderScreen> { |
|
||||||
CocosWidgetController? _cocosWidgetController; |
|
||||||
double _sliderValue = 0.0; |
|
||||||
|
|
||||||
@override |
|
||||||
void initState() { |
|
||||||
super.initState(); |
|
||||||
} |
|
||||||
|
|
||||||
@override |
|
||||||
Widget build(BuildContext context) { |
|
||||||
return Scaffold( |
|
||||||
appBar: AppBar( |
|
||||||
title: const Text('Safe Mode Screen'), |
|
||||||
), |
|
||||||
body: Card( |
|
||||||
margin: const EdgeInsets.all(8), |
|
||||||
clipBehavior: Clip.antiAlias, |
|
||||||
shape: RoundedRectangleBorder( |
|
||||||
borderRadius: BorderRadius.circular(20.0), |
|
||||||
), |
|
||||||
child: Stack( |
|
||||||
children: <Widget>[ |
|
||||||
CocosWidget( |
|
||||||
onCocosCreated: onCocosCreated, |
|
||||||
onCocosMessage: onCocosMessage, |
|
||||||
useAndroidViewSurface: true, |
|
||||||
), |
|
||||||
Positioned( |
|
||||||
bottom: 20, |
|
||||||
left: 20, |
|
||||||
right: 20, |
|
||||||
child: PointerInterceptor( |
|
||||||
child: Card( |
|
||||||
elevation: 10, |
|
||||||
child: Column( |
|
||||||
children: <Widget>[ |
|
||||||
const Padding( |
|
||||||
padding: 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) { |
|
||||||
_cocosWidgetController?.postMessage( |
|
||||||
'Cube', |
|
||||||
'SetRotationSpeed', |
|
||||||
speed, |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
void onCocosMessage(message) { |
|
||||||
print('Received message from cocos: ${message.toString()}'); |
|
||||||
} |
|
||||||
|
|
||||||
// Callback that connects the created controller to the cocos controller |
|
||||||
void onCocosCreated(controller) { |
|
||||||
_cocosWidgetController = controller; |
|
||||||
} |
|
||||||
} |
|
@ -1,96 +0,0 @@ |
|||||||
import 'package:flutter/material.dart'; |
|
||||||
import 'package:flutter_cocos_view/flutter_cocos_view.dart'; |
|
||||||
import 'package:pointer_interceptor/pointer_interceptor.dart'; |
|
||||||
|
|
||||||
class NoInteractionScreen extends StatefulWidget { |
|
||||||
const NoInteractionScreen({Key? key}) : super(key: key); |
|
||||||
|
|
||||||
@override |
|
||||||
State<NoInteractionScreen> createState() => _NoInteractionScreenState(); |
|
||||||
} |
|
||||||
|
|
||||||
class _NoInteractionScreenState extends State<NoInteractionScreen> { |
|
||||||
static final GlobalKey<ScaffoldState> _scaffoldKey = |
|
||||||
GlobalKey<ScaffoldState>(); |
|
||||||
|
|
||||||
CocosWidgetController? _cocosWidgetController; |
|
||||||
|
|
||||||
@override |
|
||||||
void initState() { |
|
||||||
super.initState(); |
|
||||||
} |
|
||||||
|
|
||||||
@override |
|
||||||
void dispose() { |
|
||||||
_cocosWidgetController?.dispose(); |
|
||||||
super.dispose(); |
|
||||||
} |
|
||||||
|
|
||||||
@override |
|
||||||
Widget build(BuildContext context) { |
|
||||||
return Scaffold( |
|
||||||
key: _scaffoldKey, |
|
||||||
appBar: AppBar( |
|
||||||
title: const Text('No Interaction Screen'), |
|
||||||
), |
|
||||||
body: Card( |
|
||||||
margin: const EdgeInsets.all(8), |
|
||||||
clipBehavior: Clip.antiAlias, |
|
||||||
shape: RoundedRectangleBorder( |
|
||||||
borderRadius: BorderRadius.circular(20.0), |
|
||||||
), |
|
||||||
child: Stack( |
|
||||||
children: [ |
|
||||||
CocosWidget( |
|
||||||
onCocosCreated: _onCocosCreated, |
|
||||||
onCocosMessage: onCocosMessage, |
|
||||||
onCocosSceneLoaded: onCocosSceneLoaded, |
|
||||||
useAndroidViewSurface: true, |
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(70)), |
|
||||||
), |
|
||||||
Positioned( |
|
||||||
bottom: 20, |
|
||||||
left: 20, |
|
||||||
right: 20, |
|
||||||
child: PointerInterceptor( |
|
||||||
child: ElevatedButton( |
|
||||||
onPressed: () { |
|
||||||
Navigator.of(context).pushNamed('/simple'); |
|
||||||
}, |
|
||||||
child: const Text('Switch Flutter Screen'), |
|
||||||
), |
|
||||||
), |
|
||||||
), |
|
||||||
], |
|
||||||
), |
|
||||||
), |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
void setRotationSpeed(String speed) { |
|
||||||
_cocosWidgetController?.postMessage( |
|
||||||
'Cube', |
|
||||||
'SetRotationSpeed', |
|
||||||
speed, |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
void onCocosMessage(message) { |
|
||||||
print('Received message from cocos: ${message.toString()}'); |
|
||||||
} |
|
||||||
|
|
||||||
void onCocosSceneLoaded(SceneLoaded? scene) { |
|
||||||
if (scene != null) { |
|
||||||
print('Received scene loaded from cocos: ${scene.name}'); |
|
||||||
print('Received scene loaded from cocos buildIndex: ${scene.buildIndex}'); |
|
||||||
} else { |
|
||||||
print('Received scene loaded from cocos: null'); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Callback that connects the created controller to the cocos controller |
|
||||||
void _onCocosCreated(controller) { |
|
||||||
controller.resume(); |
|
||||||
_cocosWidgetController = controller; |
|
||||||
} |
|
||||||
} |
|
@ -1,108 +0,0 @@ |
|||||||
import 'package:flutter/material.dart'; |
|
||||||
import 'package:flutter/services.dart'; |
|
||||||
import 'package:flutter_cocos_view/flutter_cocos_view.dart'; |
|
||||||
import 'package:pointer_interceptor/pointer_interceptor.dart'; |
|
||||||
|
|
||||||
class OrientationScreen extends StatefulWidget { |
|
||||||
const OrientationScreen({Key? key}) : super(key: key); |
|
||||||
|
|
||||||
@override |
|
||||||
State<OrientationScreen> createState() => _OrientationScreenState(); |
|
||||||
} |
|
||||||
|
|
||||||
class _OrientationScreenState extends State<OrientationScreen> { |
|
||||||
CocosWidgetController? _cocosWidgetController; |
|
||||||
double _sliderValue = 0.0; |
|
||||||
|
|
||||||
@override |
|
||||||
void initState() { |
|
||||||
super.initState(); |
|
||||||
} |
|
||||||
|
|
||||||
@override |
|
||||||
Widget build(BuildContext context) { |
|
||||||
return Scaffold( |
|
||||||
appBar: AppBar( |
|
||||||
title: const Text('Orientation Screen'), |
|
||||||
), |
|
||||||
body: Card( |
|
||||||
margin: const EdgeInsets.all(8), |
|
||||||
clipBehavior: Clip.antiAlias, |
|
||||||
shape: RoundedRectangleBorder( |
|
||||||
borderRadius: BorderRadius.circular(20.0), |
|
||||||
), |
|
||||||
child: Stack( |
|
||||||
children: <Widget>[ |
|
||||||
CocosWidget( |
|
||||||
onCocosCreated: onCocosCreated, |
|
||||||
onCocosMessage: onCocosMessage, |
|
||||||
useAndroidViewSurface: true, |
|
||||||
), |
|
||||||
Positioned( |
|
||||||
bottom: 20, |
|
||||||
left: 20, |
|
||||||
right: 20, |
|
||||||
child: PointerInterceptor( |
|
||||||
child: Card( |
|
||||||
elevation: 10, |
|
||||||
child: Column( |
|
||||||
children: <Widget>[ |
|
||||||
ElevatedButton( |
|
||||||
onPressed: () { |
|
||||||
if (MediaQuery.of(context).orientation == |
|
||||||
Orientation.portrait) { |
|
||||||
SystemChrome.setPreferredOrientations([ |
|
||||||
DeviceOrientation.landscapeLeft, |
|
||||||
DeviceOrientation.landscapeRight |
|
||||||
]); |
|
||||||
} else if (MediaQuery.of(context).orientation == |
|
||||||
Orientation.landscape) { |
|
||||||
SystemChrome.setPreferredOrientations( |
|
||||||
[DeviceOrientation.portraitUp]); |
|
||||||
} |
|
||||||
}, |
|
||||||
child: const Text("Change Orientation"), |
|
||||||
), |
|
||||||
const Padding( |
|
||||||
padding: 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) { |
|
||||||
_cocosWidgetController?.postMessage( |
|
||||||
'Cube', |
|
||||||
'SetRotationSpeed', |
|
||||||
speed, |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
void onCocosMessage(message) { |
|
||||||
print('Received message from cocos: ${message.toString()}'); |
|
||||||
} |
|
||||||
|
|
||||||
// Callback that connects the created controller to the cocos controller |
|
||||||
void onCocosCreated(controller) { |
|
||||||
_cocosWidgetController = controller; |
|
||||||
} |
|
||||||
} |
|
@ -1,112 +0,0 @@ |
|||||||
import 'package:flutter/material.dart'; |
|
||||||
import 'package:flutter_cocos_view/flutter_cocos_view.dart'; |
|
||||||
import 'package:pointer_interceptor/pointer_interceptor.dart'; |
|
||||||
|
|
||||||
class SimpleScreen extends StatefulWidget { |
|
||||||
const SimpleScreen({Key? key}) : super(key: key); |
|
||||||
|
|
||||||
@override |
|
||||||
State<SimpleScreen> createState() => _SimpleScreenState(); |
|
||||||
} |
|
||||||
|
|
||||||
class _SimpleScreenState extends State<SimpleScreen> { |
|
||||||
static final GlobalKey<ScaffoldState> _scaffoldKey = |
|
||||||
GlobalKey<ScaffoldState>(); |
|
||||||
|
|
||||||
CocosWidgetController? _cocosWidgetController; |
|
||||||
double _sliderValue = 0.0; |
|
||||||
|
|
||||||
@override |
|
||||||
void initState() { |
|
||||||
super.initState(); |
|
||||||
} |
|
||||||
|
|
||||||
@override |
|
||||||
void dispose() { |
|
||||||
_cocosWidgetController?.dispose(); |
|
||||||
super.dispose(); |
|
||||||
} |
|
||||||
|
|
||||||
@override |
|
||||||
Widget build(BuildContext context) { |
|
||||||
return Scaffold( |
|
||||||
key: _scaffoldKey, |
|
||||||
appBar: AppBar( |
|
||||||
title: const Text('Simple Screen'), |
|
||||||
), |
|
||||||
body: Card( |
|
||||||
margin: const EdgeInsets.all(0), |
|
||||||
clipBehavior: Clip.antiAlias, |
|
||||||
shape: RoundedRectangleBorder( |
|
||||||
borderRadius: BorderRadius.circular(20.0), |
|
||||||
), |
|
||||||
child: Stack( |
|
||||||
children: [ |
|
||||||
CocosWidget( |
|
||||||
onCocosCreated: _onCocosCreated, |
|
||||||
onCocosMessage: onCocosMessage, |
|
||||||
onCocosSceneLoaded: onCocosSceneLoaded, |
|
||||||
useAndroidViewSurface: false, |
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(70)), |
|
||||||
), |
|
||||||
Positioned( |
|
||||||
bottom: 0, |
|
||||||
left: 0, |
|
||||||
right: 0, |
|
||||||
child: PointerInterceptor( |
|
||||||
child: Card( |
|
||||||
elevation: 10, |
|
||||||
child: Column( |
|
||||||
children: <Widget>[ |
|
||||||
const Padding( |
|
||||||
padding: EdgeInsets.only(top: 20), |
|
||||||
child: Text("Rotation speed:"), |
|
||||||
), |
|
||||||
Slider( |
|
||||||
onChanged: (value) { |
|
||||||
setState(() { |
|
||||||
_sliderValue = value; |
|
||||||
}); |
|
||||||
setRotationSpeed(value.toString()); |
|
||||||
}, |
|
||||||
value: _sliderValue, |
|
||||||
min: 0.0, |
|
||||||
max: 1.0, |
|
||||||
), |
|
||||||
], |
|
||||||
), |
|
||||||
), |
|
||||||
), |
|
||||||
), |
|
||||||
], |
|
||||||
)), |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
void setRotationSpeed(String speed) { |
|
||||||
_cocosWidgetController?.postMessage( |
|
||||||
'Cube', |
|
||||||
'SetRotationSpeed', |
|
||||||
speed, |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
void onCocosMessage(message) { |
|
||||||
print('Received message from cocos: ${message.toString()}'); |
|
||||||
} |
|
||||||
|
|
||||||
void onCocosSceneLoaded(SceneLoaded? scene) { |
|
||||||
if (scene != null) { |
|
||||||
print('Received scene loaded from cocos: ${scene.name}'); |
|
||||||
print('Received scene loaded from cocos buildIndex: ${scene.buildIndex}'); |
|
||||||
} else { |
|
||||||
print('Received scene loaded from cocos: null'); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Callback that connects the created controller to the cocos controller |
|
||||||
void _onCocosCreated(controller) { |
|
||||||
controller.resume(); |
|
||||||
_cocosWidgetController = controller; |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue