build method

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

Called by the Router to obtain the widget tree that represents the current state.

This is called whenever the Futures returned by setInitialRoutePath, setNewRoutePath, or setRestoredRoutePath complete as well as when this notifies its clients (see the Listenable interface, which this interface includes). In addition, it may be called at other times. It is important, therefore, that the methods above do not update the state that the build method uses before they complete their respective futures.

Typically this method returns a suitably-configured Navigator. If you do plan to create a navigator, consider using the PopNavigatorRouterDelegateMixin. If state restoration is enabled for the Router using this delegate, consider providing a non-null Navigator.restorationScopeId to the Navigator returned by this method.

This method must not return null.

The context is the Router's build context.

Implementation

@override
Widget build(BuildContext context) {
  return Navigator(
      key: navigatorKey,
      initialRoute: initialRoute ?? routes.first.path,
      onGenerateRoute: (RouteSettings settings) {
        Actions.invoke(context, AppBarBuildIntent.empty());
        hideAppBar(context);
        var searchedRoute = routes.firstWhere(
          (element) => element.path == settings.name,
          orElse: () => routes.first,
        );
        _currentRoute = searchedRoute;
        var pageRoute = PageRouteBuilder(
            maintainState: searchedRoute.maintainState ?? true,
            settings: settings,
            pageBuilder: (context, __, ___) {
              if (searchedRoute.cache) {
                if (!pageCache.containsKey(searchedRoute.path)) {
                  pageCache[searchedRoute.path] =
                      searchedRoute.pageBuilder(context, settings);
                }
                return PageStorage(
                  bucket: bucket,
                  child: pageCache[searchedRoute.path]!,
                );
              }
              return searchedRoute.pageBuilder(context, settings);
            },
            transitionDuration: searchedRoute.transitionDuration ??
                Duration(milliseconds: 300),
            transitionsBuilder: searchedRoute.transitionsBuilder ??
                (_, a, b, child) => child);
        if (navigatorObservers != null) {
          navigatorObservers!.forEach((element) {
            element.didPush(pageRoute, null);
            // element.didReplace(newRoute: _currentRoute, oldRoute: _oldRoute);
          });
        }
        if (_currentRoute!.routingType == BartMenuRouteType.BOTTOM_NAV) {
          var bottomBarList = this
              .routes
              .where((element) =>
                  element.routingType == BartMenuRouteType.BOTTOM_NAV)
              .toList();
          var indexOfItem = bottomBarList.indexOf(_currentRoute!);
          Actions.invoke(context, BottomBarIndexIntent(indexOfItem));
        }
        return pageRoute;
      });
}