Reland "Inject current FlutterView into tree and make available via View.of(context) (#116924)" (#117244)

* Reland "Inject current `FlutterView` into tree and make available via `View.of(context)` (#116924)"

This reverts commit 9102f2fe0b.

* remove window placeholder
This commit is contained in:
Michael Goderbauer
2022-12-16 22:14:19 -08:00
committed by GitHub
parent 0a2a1d91cf
commit bf5fdb9f96
21 changed files with 351 additions and 108 deletions

View File

@@ -553,12 +553,24 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
EnginePhase phase = EnginePhase.sendSemanticsUpdate,
]) {
return TestAsyncUtils.guard<void>(() {
binding.attachRootWidget(widget);
binding.scheduleFrame();
return binding.pump(duration, phase);
return _pumpWidget(
binding.wrapWithDefaultView(widget),
duration,
phase,
);
});
}
Future<void> _pumpWidget(
Widget widget, [
Duration? duration,
EnginePhase phase = EnginePhase.sendSemanticsUpdate,
]) {
binding.attachRootWidget(widget);
binding.scheduleFrame();
return binding.pump(duration, phase);
}
@override
Future<List<Duration>> handlePointerEventRecord(Iterable<PointerEventRecord> records) {
assert(records != null);
@@ -697,7 +709,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
// The interval following the last frame doesn't have to be within the fullDuration.
Duration elapsed = Duration.zero;
return TestAsyncUtils.guard<void>(() async {
binding.attachRootWidget(target);
binding.attachRootWidget(binding.wrapWithDefaultView(target));
binding.scheduleFrame();
while (elapsed < maxDuration) {
await binding.pump(interval);
@@ -720,12 +732,14 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
'therefore no restoration data has been collected to restore from. Did you forget to wrap '
'your widget tree in a RootRestorationScope?',
);
final Widget widget = ((binding.renderViewElement! as RenderObjectToWidgetElement<RenderObject>).widget as RenderObjectToWidgetAdapter<RenderObject>).child!;
final TestRestorationData restorationData = binding.restorationManager.restorationData;
runApp(Container(key: UniqueKey()));
await pump();
binding.restorationManager.restoreFrom(restorationData);
return pumpWidget(widget);
return TestAsyncUtils.guard<void>(() async {
final Widget widget = ((binding.renderViewElement! as RenderObjectToWidgetElement<RenderObject>).widget as RenderObjectToWidgetAdapter<RenderObject>).child!;
final TestRestorationData restorationData = binding.restorationManager.restorationData;
runApp(Container(key: UniqueKey()));
await pump();
binding.restorationManager.restoreFrom(restorationData);
return _pumpWidget(widget);
});
}
/// Retrieves the current restoration data from the [RestorationManager].