Commit 285ab18d authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Ensure that SemanticDebugger shows SemanticTree changes from last frame (#10573)

* Ensure that SemanticDebugger shows SemanticTree changes from last frame

Fixes https://github.com/flutter/flutter/issues/10566

* Comment for clearification
parent 95544383
...@@ -65,8 +65,13 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindi ...@@ -65,8 +65,13 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindi
void _update() { void _update() {
SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) {
// We want the update to take effect next frame, so to make that // Semantic information are only available at the end of a frame and our
// explicit we call setState() in a post-frame callback. // only chance to paint them on the screen is the next frame. To achieve
// this, we call setState() in a post-frame callback. THIS PATTERN SHOULD
// NOT BE COPIED. Calling setState() in a post-frame callback is a bad
// idea as it will not schedule a frame and your app may be lagging behind
// by one frame. We manually call scheduleFrame() to force a frame and
// ensure that the semantic information are always painted on the screen.
if (mounted) { if (mounted) {
// If we got disposed this frame, we will still get an update, // If we got disposed this frame, we will still get an update,
// because the inactive list is flushed after the semantics updates // because the inactive list is flushed after the semantics updates
...@@ -74,6 +79,7 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindi ...@@ -74,6 +79,7 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> with WidgetsBindi
setState(() { setState(() {
// The generation of the _SemanticsDebuggerListener has changed. // The generation of the _SemanticsDebuggerListener has changed.
}); });
SchedulerBinding.instance.scheduleFrame();
} }
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment