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;
}());
// If supplied by a function
_routerConfig ??= onRouterConfig();
// Usually RouterConfig is last in order of precedence
// Setting this flag makes it first.
// if (_widget.routerDelegate != null) {
// } else if (_widget.home != null || (widget.routes?.isNotEmpty ?? false) || widget.onGenerateRoute != null) {
// } else if (_widget.routerConfig != null) { }
// Set the flag only if the configuration was provided
_useRouterConfig = _routerConfig != null && (_useRouterConfig ?? false);
if (_useRouterConfig!) {
// 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 = _useRouterConfig!
? null
: _routeInformationProvider ?? onRouteInformationProvider();
_routeInformationParser = _useRouterConfig!
? null
: _routeInformationParser ?? onRouteInformationParser();
_routerDelegate =
_useRouterConfig! ? null : _routerDelegate ?? onRouterDelegate();
_backButtonDispatcher = _useRouterConfig!
? null
: _backButtonDispatcher ?? onBackButtonDispatcher();
// There's possibly a preferred Locale.
// The app can specify its own Locale
if (_allowChangeLocale && App.preferredLocale != null) {
_locale = App.preferredLocale;
} else {
_locale = _locale ?? onLocale();
}
// If the locale was saved in the preferences, save the new one if any
if (_allowChangeLocale) {
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, appState: this);
if (app == null) {
//
if (_useCupertino) {
// A CupertinoApp object has been supplied.
if (cupertinoApp != null) {
app = cupertinoApp!;
//
} else if (_routerDelegate == null && !_useRouterConfig!) {
//
app = CupertinoApp(
key: key,
navigatorKey: App.navigatorKey,
theme: setiOSThemeData(context),
routes: _routes ?? onRoutes() ?? const <String, WidgetBuilder>{},
initialRoute: _initialRoute ?? onInitialRoute(),
onGenerateRoute: _onOnGenerateRoute,
onUnknownRoute: _onOnUnknownRoute,
onNavigationNotification: _onOnNavigationNotification,
navigatorObservers: _onNavigatorObservers(),
builder: _transitBuilder ?? onBuilder(),
// not needed title: , // Using instead onOnGenerateTitle parameter
onGenerateTitle: _onOnGenerateTitle,
color: _color ?? onColor() ?? Colors.blue,
locale: _locale,
localizationsDelegates: _onLocalizationsDelegates(),
localeListResolutionCallback:
_localeListResolutionCallback ?? onLocaleListResolutionCallback,
localeResolutionCallback:
_localeResolutionCallback ?? onLocaleResolutionCallback,
supportedLocales: _supportedLocales,
showPerformanceOverlay:
_showPerformanceOverlay ?? onShowPerformanceOverlay() ?? false,
checkerboardRasterCacheImages: _checkerboardRasterCacheImages ??
onCheckerboardRasterCacheImages() ??
false,
checkerboardOffscreenLayers: _checkerboardOffscreenLayers ??
onCheckerboardOffscreenLayers() ??
false,
showSemanticsDebugger:
_showSemanticsDebugger ?? onShowSemanticsDebugger() ?? false,
debugShowCheckedModeBanner: _debugShowCheckedModeBanner ??
onDebugShowCheckedModeBanner() ??
false,
shortcuts: _shortcuts ?? onShortcuts(),
actions: _actions ?? onActions(),
restorationScopeId: _restorationScopeId ?? onRestorationScopeId(),
scrollBehavior: _scrollBehavior ?? onScrollBehavior(),
// Let the parameters run before the home parameter.
home: _home ?? onHome(),
);
} else {
//
app = CupertinoApp.router(
key: key,
routeInformationProvider: _routeInformationProvider,
routeInformationParser: _routeInformationParser,
routerDelegate: _routerDelegate,
backButtonDispatcher: _backButtonDispatcher,
routerConfig: _routerConfig,
theme: setiOSThemeData(context),
builder: _transitBuilder ?? onBuilder(),
// not needed title: , // Used instead in _onOnGenerateTitle()
onGenerateTitle: _onOnGenerateTitle,
onNavigationNotification: _onOnNavigationNotification,
color: _color ?? onColor() ?? Colors.blue,
locale: _locale,
localizationsDelegates: _onLocalizationsDelegates(),
localeListResolutionCallback:
_localeListResolutionCallback ?? onLocaleListResolutionCallback,
localeResolutionCallback:
_localeResolutionCallback ?? onLocaleResolutionCallback,
supportedLocales: _supportedLocales,
showPerformanceOverlay:
_showPerformanceOverlay ?? onShowPerformanceOverlay() ?? false,
checkerboardRasterCacheImages: _checkerboardRasterCacheImages ??
onCheckerboardRasterCacheImages() ??
false,
checkerboardOffscreenLayers: _checkerboardOffscreenLayers ??
onCheckerboardOffscreenLayers() ??
false,
showSemanticsDebugger:
_showSemanticsDebugger ?? onShowSemanticsDebugger() ?? false,
debugShowCheckedModeBanner: _debugShowCheckedModeBanner ??
onDebugShowCheckedModeBanner() ??
false,
shortcuts: _shortcuts ?? onShortcuts(),
actions: _actions ?? onActions(),
restorationScopeId: _restorationScopeId ?? onRestorationScopeId(),
scrollBehavior: _scrollBehavior ?? onScrollBehavior(),
);
}
} else {
// A MaterialApp object has been supplied.
if (materialApp != null) {
//
app = materialApp!;
//
} else if (_routerDelegate == null && !_useRouterConfig!) {
//
app = MaterialApp(
key: key,
navigatorKey: App.navigatorKey,
scaffoldMessengerKey: scaffoldMessengerKey,
routes: _routes ?? onRoutes() ?? const <String, WidgetBuilder>{},
initialRoute: _initialRoute ?? onInitialRoute(),
onGenerateRoute: _onOnGenerateRoute,
onUnknownRoute: _onOnUnknownRoute,
onNavigationNotification: _onOnNavigationNotification,
navigatorObservers: _onNavigatorObservers(),
builder: _transitBuilder ?? onBuilder(),
// not needed title: , // Used instead in _onOnGenerateTitle()
onGenerateTitle: _onOnGenerateTitle,
color: _color ?? onColor() ?? Colors.blue,
theme: setThemeData(context),
darkTheme: _darkTheme ?? onDarkTheme(),
highContrastTheme: _highContrastTheme ?? onHighContrastTheme(),
highContrastDarkTheme:
_highContrastDarkTheme ?? onHighContrastDarkTheme(),
themeMode: _themeMode ?? onThemeMode() ?? ThemeMode.system,
themeAnimationDuration: _themeAnimationDuration ??
onThemeAnimationDuration() ??
const Duration(milliseconds: 200),
themeAnimationCurve: _themeAnimationCurve ??
onThemeAnimationCurve() ??
Curves.linear,
locale: _locale,
localizationsDelegates: _onLocalizationsDelegates(),
localeListResolutionCallback:
_localeListResolutionCallback ?? onLocaleListResolutionCallback,
localeResolutionCallback:
_localeResolutionCallback ?? onLocaleResolutionCallback,
supportedLocales: _supportedLocales,
debugShowMaterialGrid:
_debugShowMaterialGrid ?? onDebugShowMaterialGrid() ?? false,
showPerformanceOverlay:
_showPerformanceOverlay ?? onShowPerformanceOverlay() ?? false,
checkerboardRasterCacheImages: _checkerboardRasterCacheImages ??
onCheckerboardRasterCacheImages() ??
false,
checkerboardOffscreenLayers: _checkerboardOffscreenLayers ??
onCheckerboardOffscreenLayers() ??
false,
showSemanticsDebugger:
_showSemanticsDebugger ?? onShowSemanticsDebugger() ?? false,
debugShowCheckedModeBanner: _debugShowCheckedModeBanner ??
onDebugShowCheckedModeBanner() ??
false,
shortcuts: _shortcuts ?? onShortcuts(),
actions: _actions ?? onActions(),
restorationScopeId: _restorationScopeId ?? onRestorationScopeId(),
scrollBehavior: _scrollBehavior ?? onScrollBehavior(),
// Let the parameters run before the home parameter.
home: _home ?? onHome(),
);
} else {
//
app = MaterialApp.router(
key: key,
scaffoldMessengerKey: scaffoldMessengerKey,
routeInformationProvider: _routeInformationProvider,
routeInformationParser: _routeInformationParser,
routerDelegate: _routerDelegate,
routerConfig: _routerConfig,
backButtonDispatcher: _backButtonDispatcher,
builder: _transitBuilder ?? onBuilder(),
// not needed title: , // Used instead in _onOnGenerateTitle()
onGenerateTitle: _onOnGenerateTitle,
onNavigationNotification: _onOnNavigationNotification,
color: _color ?? onColor() ?? Colors.blue,
theme: setThemeData(context),
darkTheme: _darkTheme ?? onDarkTheme(),
highContrastTheme: _highContrastTheme ?? onHighContrastTheme(),
highContrastDarkTheme:
_highContrastDarkTheme ?? onHighContrastDarkTheme(),
themeMode: _themeMode ?? onThemeMode() ?? ThemeMode.system,
themeAnimationDuration: _themeAnimationDuration ??
onThemeAnimationDuration() ??
const Duration(milliseconds: 200),
themeAnimationCurve: _themeAnimationCurve ??
onThemeAnimationCurve() ??
Curves.linear,
locale: _locale,
localizationsDelegates: _onLocalizationsDelegates(),
localeListResolutionCallback:
_localeListResolutionCallback ?? onLocaleListResolutionCallback,
localeResolutionCallback:
_localeResolutionCallback ?? onLocaleResolutionCallback,
supportedLocales: _supportedLocales,
debugShowMaterialGrid:
_debugShowMaterialGrid ?? onDebugShowMaterialGrid() ?? false,
showPerformanceOverlay:
_showPerformanceOverlay ?? onShowPerformanceOverlay() ?? false,
checkerboardRasterCacheImages: _checkerboardRasterCacheImages ??
onCheckerboardRasterCacheImages() ??
false,
checkerboardOffscreenLayers: _checkerboardOffscreenLayers ??
onCheckerboardOffscreenLayers() ??
false,
showSemanticsDebugger:
_showSemanticsDebugger ?? onShowSemanticsDebugger() ?? false,
debugShowCheckedModeBanner: _debugShowCheckedModeBanner ??
onDebugShowCheckedModeBanner() ??
false,
shortcuts: _shortcuts ?? onShortcuts(),
actions: _actions ?? onActions(),
restorationScopeId: _restorationScopeId ?? onRestorationScopeId(),
scrollBehavior: _scrollBehavior ?? onScrollBehavior(),
);
}
}
}
// Set many variables now to null to reduce memory use
// _cleanupMemory();
return app;
}