I was trying to solve this problem for several days with no luck. I am just extremely confused with go router logic... I am building a little platform. When user opens my web app, it checks the URL path and changes several things like colors and links. It works now, but I still want to use go Router navigation. Here is working example with no Go router
Here is what I am trying to achieve:
Basically, I want several points to work, and I know it is a lot to ask, but maybe someone will help me:
- disable browser back button navigation
- when user opens my web app with any path, I want the splash screen to be displayed. But when I navigate later it should not. 3.Shell route that works only after the splash screen.
Here is part of my code:
void main() {
WidgetsFlutterBinding.ensureInitialized();
setPathUrlStrategy();
pageParams = detectPage();
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => MenuProvider()),
],
child: const MyApp(),
),
);
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Otree.pro',
theme: pageParams.themeData,
themeMode: ThemeMode.light,
debugShowMaterialGrid: false,
checkerboardRasterCacheImages: false,
showPerformanceOverlay: false,
checkerboardOffscreenLayers: false,
debugShowCheckedModeBanner: false,
showSemanticsDebugger: false,
routerConfig: GoRouter(
routes:
pageParams.routes, // Set the initial location to the splash page
// Define your other routes here
),
);
}
}
And here is how routes look like now:
routes: <RouteBase>[
GoRoute(
path: '/',
name: 'main',
builder: (BuildContext context, GoRouterState state) {
return const SplashScreenLogoV5(
next: '/catalogue',
);
},
routes: [
GoRoute(
name: 'catalogue',
path: 'catalogue',
builder: (BuildContext context, GoRouterState state) =>
const HomePage(),
routes: [
GoRoute(
name: 'home',
path: 'home',
builder: (BuildContext context, GoRouterState state) =>
const HomePage(),
),
GoRoute(
name: 'portfolio',
path: 'portfolio',
builder: (BuildContext context, GoRouterState state) {
startPage = 1;
return const HomePage();
}),
GoRoute(
name: 'price',
path: 'price',
builder: (BuildContext context, GoRouterState state) {
startPage = 2;
return const HomePage();
}),
GoRoute(
name: 'contacts',
path: 'contacts',
builder: (BuildContext context, GoRouterState state) {
startPage = 3;
return const HomePage();
}),
]),
]),
],
Here is the outcome that I get. As you see, no Splash screen, page redirects for some reason after several seconds for some reason. And the navigation is not applied yet.
So please help me...