flutter_godot 0.0.3
flutter_godot: ^0.0.3 copied to clipboard
The flutter_godot plugin can embed Godot games as Widget into Flutter applications and support two-way communication.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_godot/flutter_godot.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
_MyAppState();
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Godot',
theme: ThemeData(
brightness: Brightness.light,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.purple,
brightness: Brightness.light,
),
),
darkTheme: ThemeData(
brightness: Brightness.dark,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.purple,
brightness: Brightness.dark,
),
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
_HomePageState();
StreamSubscription? _eventSubscription;
@override
void initState() {
super.initState();
_eventSubscription = FlutterGodot.listenGodotData(
callback: (data) => debugPrint('Flutter: $data'),
);
}
@override
void dispose() {
_eventSubscription?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Flutter Godot Example')),
body: Card.outlined(
margin: const EdgeInsets.all(16),
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(12.0)),
child: FlutterGodot.ofPlayer(name: 'assets/game.pck'),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
FlutterGodot.sendDataToGodot(data: '这是Flutter发送到Godot的数据.');
},
label: const Text('发送消息到Godot'),
icon: const Icon(Icons.send),
),
);
}
}