Unverified Commit 610dc170 authored by snyiuan's avatar snyiuan Committed by GitHub

setState() will call scheduleFrame() in post-frame callback now. (#56968)

parent 3ccb160d
......@@ -83,11 +83,7 @@ class _SemanticsDebuggerState extends State<SemanticsDebugger> 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<SemanticsDebugger> with WidgetsBindi
setState(() {
// The generation of the _SemanticsDebuggerListener has changed.
});
SchedulerBinding.instance.scheduleFrame();
}
});
}
......
......@@ -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.
......
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