I have a dashboard on web. Which have common layout like sidemenu on web and on change its view will reflect.
I have setup route like this
final GoRouter _router = GoRouter(routes: <RouteBase>[
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) {
return const LoginScreen();
},
),
GoRoute(
path: '/dashboard',
builder: (BuildContext context, GoRouterState state) {
return const Dashboard();
},
routes: [
GoRoute(
path: 'home',
builder: (BuildContext context, GoRouterState state) {
return const HomeScreen();
},
),
GoRoute(
path: 'home2',
builder: (BuildContext context, GoRouterState state) {
return const Home2Screen();
},
),
]),
]);
I need to know is it not possible like I fix sidemenu and route on dashboard screen and it will change in view.
Example
class Dashboard extends StatelessWidget {
const Dashboard({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: [
SideMenu(),
Route() //Home or Home1
],
),
);
}
}
So here is side menu and route. Some if url route is /dashboard/home
or /dashboard/home1
it will change the Route view ? Because if I added a side menu in each file of home or home1 then there will be screen change visible on it which I don’t want.
2
Answers
You can use "Stateful Nested Routes" for your problem. You can actually think of the side menu as a bottom navigation bar. This way you won’t have to add a side menu to all the screens.
I put a small example for you.
And you can access more information about Nested Routes of Go Router from here: https://codewithandrea.com/articles/flutter-bottom-navigation-bar-nested-routes-gorouter/
But maybe this using does not match your path "/dashboard/home". You must check if your URL structure is important.
you can try ShellRoute
in this example, appbar with the text
App Shell
will be constant but when you change it toa
route it will renderText('Child Route "/a"')
widget inside the ShellRoute body property.