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 ?? onDebugPaintSizeEnabled() ?? false;
    // Causes each RenderBox to paint a line at each of its baselines.
    debug.debugPaintBaselinesEnabled =
        debugPaintBaselinesEnabled ?? onDebugPaintBaselinesEnabled() ?? false;
    // Causes objects like ['RenderPointerListener]' to flash when tapped.
    debug.debugPaintPointersEnabled =
        debugPaintPointersEnabled ?? onDebugPaintPointersEnabled() ?? false;
    // Causes each Layer to paint a box around its bounds.
    debug.debugPaintLayerBordersEnabled = debugPaintLayerBordersEnabled ??
        onDebugPaintLayerBordersEnabled() ??
        false;
    // Overlay a rotating set of colors when repainting layers in debug mode.
    debug.debugRepaintRainbowEnabled =
        debugRepaintRainbowEnabled ?? onDebugRepaintRainbowEnabled() ?? false;
    // Overlay a rotating set of colors when repainting text in debug mode.
    debug.debugRepaintTextRainbowEnabled = debugRepaintTextRainbowEnabled ??
        onDebugRepaintTextRainbowEnabled() ??
        false;
    // Log the dirty widgets that are built each frame.
    debug.debugPrintRebuildDirtyWidgets =
        this.debugPrintRebuildDirtyWidgets ??
            onDebugPrintRebuildDirtyWidgets() ??
            false;
    // Callback invoked for every dirty widget built each frame.
    debug.debugOnRebuildDirtyWidget =
        this.debugOnRebuildDirtyWidget ?? onDebugOnRebuildDirtyWidget();
    // Log all calls to [BuildOwner.buildScope].
    debug.debugPrintBuildScope =
        this.debugPrintBuildScope ?? onDebugPrintBuildScope() ?? false;
    // Log the call stacks that mark widgets as needing to be rebuilt.
    debug.debugPrintScheduleBuildForStacks =
        this.debugPrintScheduleBuildForStacks ??
            onDebugPrintScheduleBuildForStacks() ??
            false;
    // Log when widgets with global keys are deactivated and log when they are reactivated.
    debug.debugPrintGlobalKeyedWidgetLifecycle =
        this.debugPrintGlobalKeyedWidgetLifecycle ??
            onDebugPrintGlobalKeyedWidgetLifecycle() ??
            false;
    // Adds [Timeline] events for every Widget built.
    debug.debugProfileBuildsEnabled = this.debugProfileBuildsEnabled ??
        onDebugProfileBuildsEnabled() ??
        false;
    // Adds [Timeline] events for every user-created [Widget] built.
    debug.debugProfileBuildsEnabledUserWidgets =
        this.debugProfileBuildsEnabledUserWidgets ??
            onDebugProfileBuildsEnabledUserWidgets() ??
            false;
    // Adds debugging information to [Timeline] events related to [Widget] builds.
    debug.debugEnhanceBuildTimelineArguments =
        this.debugEnhanceBuildTimelineArguments ??
            onDebugEnhanceBuildTimelineArguments() ??
            false;
    // Show banners for deprecated widgets.
    debug.debugHighlightDeprecatedWidgets =
        this.debugHighlightDeprecatedWidgets ??
            onDebugHighlightDeprecatedWidgets() ??
            false;

    // 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;

  if (_useRouterConfig) {
    // Make the GoRouter readily available without requiring a context.
    v.App.goRouter = _routerConfig;
  } else {
    // Not to be used so not provided
    _routerConfig = null;
  }

  // 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: _onGenerateRoute,
          onUnknownRoute: _onUnknownRoute,
          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() ?? GlobalKey<ScaffoldMessengerState>(),
          routes: _routes ?? onRoutes() ?? const <String, WidgetBuilder>{},
          initialRoute: _initialRoute ?? onInitialRoute(),
          onGenerateRoute: _onGenerateRoute,
          onUnknownRoute: _onUnknownRoute,
          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(context),
          highContrastTheme:
              _highContrastTheme ?? onHighContrastTheme(context),
          highContrastDarkTheme:
              _highContrastDarkTheme ?? onHighContrastDarkTheme(context),
          themeMode: _themeMode ?? onThemeMode(),
          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() ?? GlobalKey<ScaffoldMessengerState>(),
          // 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(context),
          highContrastTheme:
              _highContrastTheme ?? onHighContrastTheme(context),
          highContrastDarkTheme:
              _highContrastDarkTheme ?? onHighContrastDarkTheme(context),
          themeMode: _themeMode ?? onThemeMode(),
          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;
}