From 610dc170d95fadb5dff8f72022ca9dd528f45540 Mon Sep 17 00:00:00 2001 From: snyiuan <48586959+snyiuan@users.noreply.github.com> Date: Thu, 14 May 2020 00:37:02 +0800 Subject: [PATCH] setState() will call scheduleFrame() in post-frame callback now. (#56968) --- .../flutter/lib/src/widgets/semantics_debugger.dart | 7 +------ .../flutter/test/widgets/semantics_debugger_test.dart | 10 ++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/flutter/lib/src/widgets/semantics_debugger.dart b/packages/flutter/lib/src/widgets/semantics_debugger.dart index f25fd23fee..887416b271 100644 --- a/packages/flutter/lib/src/widgets/semantics_debugger.dart +++ b/packages/flutter/lib/src/widgets/semantics_debugger.dart @@ -83,11 +83,7 @@ class _SemanticsDebuggerState extends State with WidgetsBindi SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { // 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. + // this, we call setState() in a post-frame callback. if (mounted) { // If we got disposed this frame, we will still get an update, // because the inactive list is flushed after the semantics updates @@ -95,7 +91,6 @@ class _SemanticsDebuggerState extends State with WidgetsBindi setState(() { // The generation of the _SemanticsDebuggerListener has changed. }); - SchedulerBinding.instance.scheduleFrame(); } }); } diff --git a/packages/flutter/test/widgets/semantics_debugger_test.dart b/packages/flutter/test/widgets/semantics_debugger_test.dart index 0aa64539bc..f80cfaa987 100644 --- a/packages/flutter/test/widgets/semantics_debugger_test.dart +++ b/packages/flutter/test/widgets/semantics_debugger_test.dart @@ -10,6 +10,16 @@ import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { + testWidgets('SemanticsDebugger will schedule a frame', (WidgetTester tester) async { + await tester.pumpWidget( + SemanticsDebugger( + child: Container(), + ), + ); + + expect(tester.binding.hasScheduledFrame, isTrue); + }); + testWidgets('SemanticsDebugger smoke test', (WidgetTester tester) async { // This is a smoketest to verify that adding a debugger doesn't crash.