lumi
lumi

Reputation: 11

Whats the alternative to if (routeSettings.isInitialRoute) in flutter

since isInitialRoute was removed from flutter, what else could i use instead? (the initial route is / , if we can address that directly)

    Widget build(BuildContext context) {
      return WillPopScope(
        child: Navigator(
          key: navigationKey,
          initialRoute: initialRoute,
          onGenerateRoute: (RouteSettings routeSettings) {
            WidgetBuilder builder = routes[routeSettings.name];
            if (routeSettings.isInitialRoute) {
              return PageRouteBuilder(
                pageBuilder: (context, __, ___) => builder(context),
                settings: routeSettings,
              );
            } else {
              return MaterialPageRoute(
                builder: builder,
                settings: routeSettings,
              );
            }
          },
        ),
        onWillPop: () {
          if(navigationKey.currentState.canPop()) {
            navigationKey.currentState.pop();
            return Future<bool>.value(false);
          }
          return Future<bool>.value(true);
        },
      );
    }

Upvotes: 1

Views: 1541

Answers (1)

Wimukthi Rajapaksha
Wimukthi Rajapaksha

Reputation: 1019

You have to use settings.name=='/' as routeSettings.isInitialRoute is deprecated. Refer this

Upvotes: 3

Related Questions