flutter-stats-fl
flutter-stats-fl copied to clipboard
Control whether FPS is enabled dynamically
Make StatsFlState public and add a new method updateEnable() to control isEnabled.
for example:
final statsflKey = GlobalKey<StatsFlState>();
Widget app = StatsFl(
key: statsflKey,
isEnabled: true,
showText: true,
align: Alignment.centerLeft,
maxFps: 120,
child: Center(
child: ElevatedButton(
onPressed: () {
if (statsflKey.currentState?.isEnabled == true) {
statsflKey.currentState?.updateEnable(false);
} else {
statsflKey.currentState?.updateEnable(true);
}
},
child: Text("Toggle"),
),
),
);
Can't you just do:
Widget app = StatsFl(
key: statsflKey,
isEnabled: _showStats,
...
);
and
onPressed: () {
setState((){
_showStats = !_showStats;
});},
Maybe we need to add a didUpdateWidget hook to start/stop the timer when isEnabled changes?
Thanks for repling, this PR will be closed.