MaterialApp constructor

MaterialApp({Key key, GlobalKey<NavigatorState> navigatorKey, Widget home, Map<String, WidgetBuilder> routes: const {}, String initialRoute, RouteFactory onGenerateRoute, RouteFactory onUnknownRoute, List<NavigatorObserver> navigatorObservers: const [], TransitionBuilder builder, String title: '', GenerateAppTitle onGenerateTitle, Color color, ThemeData theme, Locale locale, Iterable<LocalizationsDelegate> localizationsDelegates, LocaleResolutionCallback localeResolutionCallback, Iterable<Locale> supportedLocales: const [const Locale('en', 'US')], bool debugShowMaterialGrid: false, bool showPerformanceOverlay: false, bool checkerboardRasterCacheImages: false, bool checkerboardOffscreenLayers: false, bool showSemanticsDebugger: false, bool debugShowCheckedModeBanner: true })

Creates a MaterialApp.

At least one of home, routes, onGenerateRoute, or builder must be non-null. If only routes is given, it must include an entry for the Navigator.defaultRouteName (/), since that is the route used when the application is launched with an intent that specifies an otherwise unsupported route.

This class creates an instance of WidgetsApp.

The boolean arguments, routes, and navigatorObservers, must not be null.

Implementation

MaterialApp({ // can't be const because the asserts use methods on Map :-(
  Key key,
  this.navigatorKey,
  this.home,
  this.routes: const <String, WidgetBuilder>{},
  this.initialRoute,
  this.onGenerateRoute,
  this.onUnknownRoute,
  this.navigatorObservers: const <NavigatorObserver>[],
  this.builder,
  this.title: '',
  this.onGenerateTitle,
  this.color,
  this.theme,
  this.locale,
  this.localizationsDelegates,
  this.localeResolutionCallback,
  this.supportedLocales: const <Locale>[const Locale('en', 'US')],
  this.debugShowMaterialGrid: false,
  this.showPerformanceOverlay: false,
  this.checkerboardRasterCacheImages: false,
  this.checkerboardOffscreenLayers: false,
  this.showSemanticsDebugger: false,
  this.debugShowCheckedModeBanner: true,
}) : assert(routes != null),
     assert(navigatorObservers != null),
     assert(
       home == null ||
       !routes.containsKey(Navigator.defaultRouteName),
       'If the home property is specified, the routes table '
       'cannot include an entry for "/", since it would be redundant.'
     ),
     assert(
       builder != null ||
       home != null ||
       routes.containsKey(Navigator.defaultRouteName) ||
       onGenerateRoute != null ||
       onUnknownRoute != null,
       'Either the home property must be specified, '
       'or the routes table must include an entry for "/", '
       'or there must be on onGenerateRoute callback specified, '
       'or there must be an onUnknownRoute callback specified, '
       'or the builder property must be specified, '
       'because otherwise there is nothing to fall back on if the '
       'app is started with an intent that specifies an unknown route.'
     ),
     assert(
       (home != null ||
        routes.isNotEmpty ||
        onGenerateRoute != null ||
        onUnknownRoute != null)
       ||
       (builder != null &&
        navigatorKey == null &&
        initialRoute == null &&
        navigatorObservers.isEmpty),
       'If no route is provided using '
       'home, routes, onGenerateRoute, or onUnknownRoute, '
       'a non-null callback for the builder property must be provided, '
       'and the other navigator-related properties, '
       'navigatorKey, initialRoute, and navigatorObservers, '
       'must have their initial values '
       '(null, null, and the empty list, respectively).'
     ),
     assert(title != null),
     assert(debugShowMaterialGrid != null),
     assert(showPerformanceOverlay != null),
     assert(checkerboardRasterCacheImages != null),
     assert(checkerboardOffscreenLayers != null),
     assert(showSemanticsDebugger != null),
     assert(debugShowCheckedModeBanner != null),
     super(key: key);