On application start i have a few configuration pages (that can be skipped by user) that user setup once, and finally ends up in dashboard page.
Possible navigation flows (depend on what user already setup, and what skipped in the past):
'/' -> '/dashboard'
'/' -> '/language' -> '/dashboard'
'/' -> '/welcome'/ -> '/dashboard'
'/' -> '/welcome'/ -> '/language' -> '/dashboard'
If i go from /welcome
to /language
I use context.push('/language')
to be able to navigate back - but i am aware that it can be redirected to /dashboard
. so if i go from anywhere to /dashboard
, i always want to end up with clear navigation history, so that if user click backButton on dashboard, the application should shut down and there is no back arrow in dashboard AppBar.
final router = GoRouter(
routes: <GoRoute>[
GoRoute(
path: '/',
redirect: (_, __) => '/welcome',
),
GoRoute(
path: '/welcome',
builder: (_, __) => const WelcomePage(),
redirect: (_, __) async {
final skip = await ...
if (skip) {
return '/language';
}
return null;
},
),
GoRoute(
path: '/language',
builder: (_, __) => const LanguagePage(),
redirect: (_, __) async {
final skip = await ...
if (skip) {
/*
* TODO MAKE SOME MAGIC HERE TO CLEAR HISTORY
*/
return '/dashboard';
}
return null;
},
),
GoRoute(
path: '/dashboard',
builder: (_, __) => const DashboardPage(),
),
],
);