Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not navigate to initial route. The requested route name was: "/entries" #150

Closed
devloic opened this issue Mar 15, 2024 · 2 comments · Fixed by #151
Closed

Could not navigate to initial route. The requested route name was: "/entries" #150

devloic opened this issue Mar 15, 2024 · 2 comments · Fixed by #151

Comments

@devloic
Copy link

devloic commented Mar 15, 2024

on flutter web
When one manually changes the url so it points to an existing route (ex: entries) , the app will print an exception on the console and reload the "jobs" route (when signed in). The message in the console only appears when the app runs locally, on firebase hosting there is no message (the reload to "jobs" still occurs).

This behavior makes it very complicated to implement "email link authentication" with firebase auth because the email signin logic which is under another route will never run.
I blamed go_router which I learnt to hate and was about to rip it of the app violently when I discovered that the problem was actually AppStartupWidget . ( https://stackoverflow.com/questions/64236640/there-was-no-corresponding-route-through-flutter-web-url )
AppStartupWidget which warms up the providers confuses flutter's navigation because it first creates AppStartupLoadingWidget which is a MaterialApp() but onLoaded(context) creates a MaterialApp with MaterialApp.router(). For some reason the first MaterialApp will handle routing when one changes the url manually and redirects to "jobs".

final appStartupState = ref.watch(appStartupProvider);
return appStartupState.when(
data: (_) => onLoaded(context),
loading: () => const AppStartupLoadingWidget(),
error: (e, st) => AppStartupErrorWidget(
message: e.toString(),
onRetry: () => ref.invalidate(appStartupProvider),
),
);

starter

In order to correct that behavior it was necessary to avoid using AsyncValue.when because it was returning a MaterialApp() first during the loading. I moved the logic to main using the technique (Randal Schwartz) explained here :
https://www.youtube.com/watch?v=LEk6AWroib8

My changes: master...devloic:starter_architecture_flutter_firebase:master

UPDATE:
While redacting this issue I found an even simpler solution: remove "MaterialApp(home: Scaffold(body:" and just keep the Center in both AppStartupLoadingWidget and AppStartupErrorWidget. No more MaterialApp and the urls work again.

Related issue
#148

@bizz84
Copy link
Owner

bizz84 commented Mar 16, 2024

@devloic Thanks for reporting this and yes, I only realized recently that AppStartupWidget messes up URL navigation and deep links.

I'll review your proposed solution and experiment a bit more, and hopefully I can fix this once and for all.

@bizz84
Copy link
Owner

bizz84 commented Mar 17, 2024

I started working on a fix here:

#151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants