Stack Exchange
Flutter settings.name incomplete on page reload
I have a route setup. In the browser, it looks like this.
localhost:1234/#/member/D8B5D7F17639A28FE83C47AFFC69592E?

I use an onGenerateRoute function like this (very truncated)
Route<dynamic> generateRoute(RouteSettings settings) {
  Uri uri = Uri.parse(settings.name ?? "");
  final Map args = (settings.arguments ?? {}) as Map<dynamic, dynamic>;
  List<String> urlParts = uri.path.substring(1).split("/");
  urlParts[0] = '/' + urlParts[0];
  Widget selectedRoute = () {
    print(urlParts);
    if (urlParts[0] == '/member') {
      return CardGuestViewProfile(memberCode: urlParts[1]);
    }
    return AppHomeScreen();
  }()

  return MaterialPageRoute(builder: (context) => selectedRoute,
    settings: RouteSettings(name: settings.name));
}

Everything works great. The print statement outputs:
[/member, D8B5D7F17639A28FE83C47AFFC69592E]

However, if I refresh the page. The visible url is not overwritten. It still says
localhost:1234/#/member/D8B5D7F17639A28FE83C47AFFC69592E?

But I get Unexpected null value for urlParts[1] because urlParts now prints as
[/member]


Are you using navigator v2?

@YeasinSheikh No

I will encourage you to check navigator2.  you can find some packages like go route/auto route  or you can directly use nav2, this is my practice level  might help you.

I'm checking it out. Thanks. I'd still like to understand why I'm encountering this issue, if anyone knows.

As @YeasinSheikh pointed out, to get this working you need Navigator 2.0. You need to have a logic that translates the current URL in the browser to route information in Flutter if you are on the web platform. Look for RouteInformationParser, especially parseRouteInformation.

The basic difference is that Navigator 1.0 is imperative, means it executes route changes and provides some basic functionality, but does not expose the navigation stack itself, which is needed if the user can freely navigate, enter a URL, use the back button of browser etc.

On the other hand side, Navigator 2.0 is declarative, and with that you have full access to the navigation stack, and with a correct (and littlebit complicated) setup you can parse the current route in the browser's address bar and reflect changes in browser history.

@PeterKoltai It's disappointing how clean Navigator 1.0 is and how messy 2.0 is but I'm working with it.

@RegularJo I agree, there's been a lot of discussion about how controversial this API is. I don't use auto_route, but it might worth checking out, see this article for example.
