From 285ab18dde13b19304095fb3b62f5f9acae65677 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Thu, 8 Jun 2017 15:25:22 -0700 Subject: [PATCH] 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 --- .../flutter/lib/src/widgets/semantics_debugger.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/widgets/semantics_debugger.dart b/packages/flutter/lib/src/widgets/semantics_debugger.dart index ac888f8f62..f6e1c2e7cc 100644 --- a/packages/flutter/lib/src/widgets/semantics_debugger.dart +++ b/packages/flutter/lib/src/widgets/semantics_debugger.dart @@ -65,8 +65,13 @@ class _SemanticsDebuggerState extends State with WidgetsBindi void _update() { SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { - // We want the update to take effect next frame, so to make that - // explicit we call setState() in a post-frame callback. + // Semantic information are only available at the end of a frame and our + // 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 we got disposed this frame, we will still get an update, // because the inactive list is flushed after the semantics updates @@ -74,6 +79,7 @@ class _SemanticsDebuggerState extends State with WidgetsBindi setState(() { // The generation of the _SemanticsDebuggerListener has changed. }); + SchedulerBinding.instance.scheduleFrame(); } }); }