Ensure frame is scheduled when root widget is attached (#40105)

This commit is contained in:
Michael Goderbauer
2019-09-10 13:26:09 -07:00
committed by GitHub
parent 2bc8f999f7
commit 3f98fb7949
2 changed files with 20 additions and 0 deletions

View File

@@ -940,6 +940,9 @@ class RenderObjectToWidgetAdapter<T extends RenderObject> extends RenderObjectWi
owner.buildScope(element, () {
element.mount(null, null);
});
// This is most likely the first time the framework is ready to produce
// a frame. Ensure that we are asked for one.
SchedulerBinding.instance.ensureVisualUpdate();
} else {
element._newWidget = this;
element.markNeedsBuild();

View File

@@ -0,0 +1,17 @@
// Copyright 2019 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
void main() {
test('attachRootWidget will schedule a frame', () async {
final WidgetsFlutterBinding binding = WidgetsFlutterBinding.ensureInitialized();
expect(SchedulerBinding.instance.hasScheduledFrame, isFalse);
binding.attachRootWidget(const Placeholder());
expect(SchedulerBinding.instance.hasScheduledFrame, isTrue);
});
}