wrapWithDefaultView method

Widget wrapWithDefaultView(
  1. Widget rootWidget
)

Used by runApp to wrap the provided rootWidget in the default View.

The View determines into what FlutterView the app is rendered into. This is currently PlatformDispatcher.implicitView from platformDispatcher. This method will throw a StateError if the PlatformDispatcher.implicitView is null.

The rootWidget widget provided to this method must not already be wrapped in a View.

Implementation

Widget wrapWithDefaultView(Widget rootWidget) {
  if (platformDispatcher.implicitView == null) {
    throw StateError(
      'The app requested a view, but the platform did not provide one.\n'
      'This is likely because the app called `runApp` to render its root '
      'widget, which expects the platform to provide a default view to '
      'render into (the "implicit" view).\n'
      'However, the platform likely has multi-view mode enabled, which does '
      'not create this default "implicit" view.\n'
      'Try using `runWidget` instead of `runApp` to start your app.\n'
      '`runWidget` allows you to provide a `View` widget, without requiring '
      'a default view.'
      '${kIsWeb?"\nSee: https://flutter.dev/to/web-multiview-runwidget" : ""}'
    );
  }

  return View(
    view: platformDispatcher.implicitView!,
    deprecatedDoNotUseWillBeRemovedWithoutNoticePipelineOwner: pipelineOwner,
    deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView: renderView,
    child: rootWidget,
  );
}