Browser URL bar is not updated by RouteInformationParser.restoreRouteInformation in staging environment
I just had a similar problem and found out that I forgot to implement currentConfiguration of RouterDelegate. That made the difference.
Marc Brun
Updated on December 25, 2022Comments
-
Marc Brun over 1 year
I work with my team on a Flutter web app, and I am trying to change the browser url according to the page the user is inside our app.
I have managed to make this work on my local machine with the top part of our app looking like this:
final app = ChangeNotifierProvider<RouteModel>( create: (_) => RouteModel( visitStack: ListQueue.from([visit ?? PageVisit.home()]), ), child: Builder(builder: (BuildContext context) => MyApp()), ); runApp(app);
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { final routeModel = context.watch<RouteModel>(); final _routerDelegate = MyRouterDelegate(routeModel); final _routeInformationParser = MyRouteInformationParser(routeModel); final _routeInformationProvider = MyRouteInformationProvider(routeModel); return MaterialApp.router( title: 'My App', routerDelegate: _routerDelegate, routeInformationParser: _routeInformationParser, ); } }
The
RouteModel
is a hub that receives calls from pages to navigate to other pages, and handles url, args and other helper functions for the internal app state.From what I understood of the Flutter docs, the RouteInformationParser.restoreRouteInformation is supposed to change the browser URL when the app state changes. If a RouteInformationProvider is provided to the MaterialApp.router, its function routerReportsNewRouteInformation may override RouteInformationParser.restoreRouteInformation.
The browser URL is changed on navigation as expected on our local machines, but not on our staging environment.
Using some logging info, I know that the following functions are called when I navigate to a new page, both on local machine and staging environment:
- MyRouteInformationProvider.value (4 times)
- MyRouteInformationParser.parseRouteInformation
- Router.navigate // (I call it from the top widget of the app, common to all sub-pages)
- MyRouterDelegate.currentConfiguration
- MyRouteInformationParser.restoreRouteInformation
- MyRouteInformationProvider.routerReportsNewRouteInformation
If I remove the RouteInformationProvider, I can also remove the Router.navigate call and the browser URL still gets updated locally.
My question is: is there a specific reason/configuration that could make the staging environment prevent the browser url to change?
Output of
flutter --version
:Flutter 1.23.0-18.1.pre • channel beta • https://github.com/flutter/flutter.git Framework • revision 198df796aa (6 weeks ago) • 2020-10-15 12:04:33 -0700 Engine • revision 1d12d82d9c Tools • Dart 2.11.0 (build 2.11.0-213.1.beta)
Output of
flutter doctor
:Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel beta, 1.23.0-18.1.pre, on Mac OS X 10.15.7 19H2 x86_64, locale fr-FR) [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) [✓] Xcode - develop for iOS and macOS (Xcode 11.7) [✓] Chrome - develop for the web [✓] Android Studio (version 3.5) [✓] Connected device (2 available) • No issues found!