Files
flame/packages/flame_devtools/lib/widgets/debug_mode_button.dart
Lukas Klingsbo bf5d68e9b5 feat: Component tree for the devtools extension tab (#3094)
This PR creates a devtools extension tab for Flame where you can:
 * Turn on `debugMode` for a chosen component or the whole tree
 * See the component tree
 * Play, pause and step the game loop.

[Screencast from 2024-03-24
22-09-55.webm](https://github.com/flame-engine/flame/assets/744771/82217afb-e096-4375-a892-b59e1be6d7ec)
2024-03-25 20:36:17 +00:00

52 lines
1.2 KiB
Dart

import 'package:flame_devtools/repository.dart';
import 'package:flutter/material.dart';
class DebugModeButton extends StatefulWidget {
const DebugModeButton({super.key, this.id});
final int? id;
@override
Key? get key => super.key ?? ValueKey(id);
@override
State<DebugModeButton> createState() => _DebugModeButtonState();
}
class _DebugModeButtonState extends State<DebugModeButton> {
Future<bool>? _debugMode;
@override
void initState() {
_debugMode = Repository.getDebugMode(id: widget.id);
super.initState();
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _debugMode,
builder: (context, value) {
final buttonPrefix = switch (value.data) {
null => 'Loading',
true => 'Disable',
false => 'Enable',
};
return ElevatedButton(
onPressed: value.data == null
? null
: () {
setState(
() {
_debugMode = Repository.swapDebugMode(id: widget.id);
},
);
},
child: Text('$buttonPrefix Debug Mode'),
);
},
);
}
}