Created
October 1, 2023 14:21
-
-
Save SaltySpaghetti/50b9d97b6a824df8f9b2238be0fd4d36 to your computer and use it in GitHub Desktop.
FPS Counter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FPSCounter extends StatefulWidget { | |
const FPSCounter({super.key}); | |
@override | |
State<FPSCounter> createState() => _FPSCounterState(); | |
} | |
class _FPSCounterState extends State<FPSCounter> { | |
int fps = 0; | |
@override | |
void initState() { | |
super.initState(); | |
WidgetsBinding.instance.addTimingsCallback((timings) { | |
final FrameTimingSummarizer frameTimes = FrameTimingSummarizer(timings); | |
setState(() { | |
fps = 1000000.0 ~/ frameTimes.averageFrameBuildTime.inMicroseconds; | |
}); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Text('FPS: $fps'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment