restartAndRestore method Null safety

Future<void> restartAndRestore ()

Simulates restoring the state of the widget tree after the application is restarted.

The method grabs the current serialized restoration data from the RestorationManager, takes down the widget tree to destroy all in-memory state, and then restores the widget tree from the serialized restoration data.

Implementation

Future<void> restartAndRestore() async {
  assert(
    binding.restorationManager.debugRootBucketAccessed,
    'The current widget tree did not inject the root bucket of the RestorationManager and '
    '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.child!;
  final TestRestorationData restorationData = binding.restorationManager.restorationData;
  runApp(Container(key: UniqueKey()));
  await pump();
  binding.restorationManager.restoreFrom(restorationData);
  return pumpWidget(widget);
}