You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
5.5 KiB
168 lines
5.5 KiB
// 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;
|
|
}
|
|
}
|
|
|