buildIn method
Override to impose your own WidgetsApp (like CupertinoApp or MaterialApp)
Implementation
@override
Widget buildIn(BuildContext context) {
//
Widget? app;
assert(() {
/// Highlights UI while debugging.
debug.debugPaintSizeEnabled = debugPaintSizeEnabled;
debug.debugPaintBaselinesEnabled = debugPaintBaselinesEnabled;
debug.debugPaintPointersEnabled = debugPaintPointersEnabled;
debug.debugPaintLayerBordersEnabled = debugPaintLayerBordersEnabled;
debug.debugRepaintRainbowEnabled = debugRepaintRainbowEnabled;
debug.debugRepaintTextRainbowEnabled = debugRepaintTextRainbowEnabled;
/// Log how widgets are built
debug.debugPrintRebuildDirtyWidgets = this.debugPrintRebuildDirtyWidgets;
debug.debugOnRebuildDirtyWidget = this.debugOnRebuildDirtyWidget;
debug.debugPrintBuildScope = this.debugPrintBuildScope;
debug.debugPrintScheduleBuildForStacks =
this.debugPrintScheduleBuildForStacks;
debug.debugPrintGlobalKeyedWidgetLifecycle =
this.debugPrintGlobalKeyedWidgetLifecycle;
debug.debugProfileBuildsEnabled = this.debugProfileBuildsEnabled;
debug.debugProfileBuildsEnabledUserWidgets =
this.debugProfileBuildsEnabledUserWidgets;
debug.debugEnhanceBuildTimelineArguments =
this.debugEnhanceBuildTimelineArguments;
debug.debugHighlightDeprecatedWidgets =
this.debugHighlightDeprecatedWidgets;
return true;
}());
// A Route Configuration was provided
final _useRouter =
routerConfig != null && (home == null || (useRouterConfig ?? false));
// Set the flag if not provided or home == null;
useRouterConfig ??= _useRouter;
if (_useRouter) {
// Make the GoRouter readily available without requiring a context.
App.goRouter = routerConfig;
}
// If the routerConfig is to be used, the others must all be null.
_routeInformationProvider = _useRouter
? null
: _routeInformationProvider ?? onRouteInformationProvider();
_routeInformationParser = _useRouter
? null
: _routeInformationParser ?? onRouteInformationParser();
_routerDelegate = _useRouter ? null : _routerDelegate ?? onRouterDelegate();
_backButtonDispatcher =
_useRouter ? null : _backButtonDispatcher ?? onBackButtonDispatcher();
// There's possibly a preferred Locale.
Locale? _preferredLocale;
// The app can specify its own Locale
if (_allowChangeLocale) {
_preferredLocale = App.preferredLocale;
}
_locale = _preferredLocale ?? _locale ?? onLocale();
// If the locale was saved in the preferences, save the new one if any
if (_preferredLocale != null) {
App.saveLocale(_locale);
}
// Assign to the L10n
// IMPORTANT assign L10n.locale before L10n.supportedLocales
L10n.locale = _locale;
// Can't be empty
// Thus, only set once!
if (_supportedLocales.isEmpty) {
_supportedLocales =
onSupportedLocales() ?? const <Locale>[Locale('en', 'US')];
// Still empty
if (_supportedLocales.isEmpty) {
_supportedLocales = const <Locale>[Locale('en', 'US')];
}
}
// Note, if it's not empty, it's not set
// Can only set once!
L10n.supportedLocales = _supportedLocales;
// An app builder may instead by supplied.
app = buildApp(context);
if (app == null) {
//
if (_useCupertino) {
// A CupertinoApp object has been supplied.
if (cupertinoApp != null) {
app = cupertinoApp!;
//
} else if (_routerDelegate == null && !_useRouter) {
//
app = CupertinoApp(
key: key,
navigatorKey: App.navigatorKey,
theme: setiOSThemeData(context),
routes: routes,
initialRoute: initialRoute,
onGenerateRoute: onGenerateRoute,
onUnknownRoute: onUnknownRoute,
onNavigationNotification: onNavigationNotification,
navigatorObservers: _onNavigatorObservers(),
builder: transitBuilder,
// not needed title: , // Used instead in _onOnGenerateTitle()
onGenerateTitle: onGenerateTitle,
color: color,
locale: _locale,
localizationsDelegates: localizationsDelegates,
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: _supportedLocales,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
shortcuts: shortcuts,
actions: actions,
restorationScopeId: restorationScopeId,
scrollBehavior: scrollBehavior,
// Let the parameters run before the home parameter.
home: home,
);
} else {
//
app = CupertinoApp.router(
key: key,
routeInformationProvider: _routeInformationProvider,
routeInformationParser: _routeInformationParser,
routerDelegate: _routerDelegate,
backButtonDispatcher: _backButtonDispatcher,
routerConfig: routerConfig,
theme: setiOSThemeData(context),
builder: transitBuilder,
// not needed title: , // Used instead in _onOnGenerateTitle()
onGenerateTitle: onGenerateTitle,
onNavigationNotification: onNavigationNotification,
color: color,
locale: _locale,
localizationsDelegates: localizationsDelegates,
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: _supportedLocales,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
shortcuts: shortcuts,
actions: actions,
restorationScopeId: restorationScopeId,
scrollBehavior: scrollBehavior,
);
}
} else {
// A MaterialApp object has been supplied.
if (materialApp != null) {
//
app = materialApp!;
//
} else if (_routerDelegate == null && !_useRouter) {
//
app = MaterialApp(
key: key,
navigatorKey: App.navigatorKey,
scaffoldMessengerKey: scaffoldMessengerKey,
routes: routes,
initialRoute: initialRoute,
onGenerateRoute: onGenerateRoute,
onUnknownRoute: onUnknownRoute,
onNavigationNotification: onNavigationNotification,
navigatorObservers: _onNavigatorObservers(),
builder: transitBuilder,
// not needed title: , // Used instead in _onOnGenerateTitle()
onGenerateTitle: onGenerateTitle,
color: color,
theme: setThemeData(context),
darkTheme: darkTheme,
highContrastTheme: highContrastTheme,
highContrastDarkTheme: highContrastDarkTheme,
themeMode: themeMode,
themeAnimationDuration: themeAnimationDuration,
themeAnimationCurve: themeAnimationCurve,
locale: _locale,
localizationsDelegates: localizationsDelegates,
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: _supportedLocales,
debugShowMaterialGrid: debugShowMaterialGrid,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
shortcuts: shortcuts,
actions: actions,
restorationScopeId: restorationScopeId,
scrollBehavior: scrollBehavior,
// Let the parameters run before the home parameter.
home: home,
);
} else {
//
app = MaterialApp.router(
key: key,
scaffoldMessengerKey: scaffoldMessengerKey,
routeInformationProvider: _routeInformationProvider,
routeInformationParser: _routeInformationParser,
routerDelegate: _routerDelegate,
routerConfig: routerConfig,
backButtonDispatcher: _backButtonDispatcher,
builder: transitBuilder,
// not needed title: , // Used instead in _onOnGenerateTitle()
onGenerateTitle: onGenerateTitle,
onNavigationNotification: onNavigationNotification,
color: color,
theme: setThemeData(context),
darkTheme: darkTheme,
highContrastTheme: highContrastTheme,
highContrastDarkTheme: highContrastDarkTheme,
themeMode: themeMode,
themeAnimationDuration: themeAnimationDuration,
themeAnimationCurve: themeAnimationCurve,
locale: _locale,
localizationsDelegates: localizationsDelegates,
localeListResolutionCallback: localeListResolutionCallback,
localeResolutionCallback: localeResolutionCallback,
supportedLocales: _supportedLocales,
debugShowMaterialGrid: debugShowMaterialGrid,
showPerformanceOverlay: showPerformanceOverlay,
checkerboardRasterCacheImages: checkerboardRasterCacheImages,
checkerboardOffscreenLayers: checkerboardOffscreenLayers,
showSemanticsDebugger: showSemanticsDebugger,
debugShowCheckedModeBanner: debugShowCheckedModeBanner,
shortcuts: shortcuts,
actions: actions,
restorationScopeId: restorationScopeId,
scrollBehavior: scrollBehavior,
);
}
}
}
return app;
}