builder method

  1. @override
Widget builder(
  1. BuildContext context
)
override

Use this function instead of the build() function

dartdoc: {@category StateX class}

Implementation

@override
Widget builder(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;

    // If running in a tester. Don't open the Widget tree inspector.
    if (WidgetsBinding.instance is WidgetsFlutterBinding) {
      WidgetsBinding.instance.debugShowWidgetInspectorOverrideNotifier.value =
          _debugShowWidgetInspector ?? false;
    }
    return true;
  }());

  // If supplied by a function
  _routerConfig ??= onRouterConfig();

  // 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.
    v.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 && v.App.preferredLocale != null) {
    _locale = v.App.preferredLocale;
  } else {
    _locale = _locale ?? onLocale();
  }

  // If the locale was saved in the preferences, save the new one if any
  if (_allowChangeLocale) {
    v.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(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: 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: navigatorKey,
          scaffoldMessengerKey: _scaffoldMessengerKey ??=
              onScaffoldMessengerKey(), // update getter
          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(),
          themeAnimationStyle:
              _themeAnimationStyle ?? onThemeAnimationStyle(),
          // Let the parameters run before the home parameter.
          home: _home ?? onHome(),
        );
      } else {
        //
        app = MaterialApp.router(
          key: key,
          scaffoldMessengerKey: _scaffoldMessengerKey ??=
              onScaffoldMessengerKey(), // update getter
          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(),
          themeAnimationStyle:
          _themeAnimationStyle ?? onThemeAnimationStyle(),
        );
      }
    }
  }
  return app;
}