-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed as not planned
Closed as not planned
Copy link
Description
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
void main() => runApp(App());
final GoRouter _router = GoRouter(
routes: <RouteBase>[
ShellRoute(
builder: (context, state, child) {
print("Shell: ${state.location}");
return child;
},
routes: <GoRoute>[
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) {
return MyHomePage();
},
),
GoRoute(
path: '/b',
builder: (BuildContext context, GoRouterState state) {
return MyHomePageB();
},
),
])
],
);
class App extends StatelessWidget {
App({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: _router,
title: 'GoRouter Example',
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
final st = GoRouterState.of(context);
print("locA: ${st.location}");
return Scaffold(
appBar: AppBar(
title: const Text("A"),
),
body: Column(children: [
TextButton(child: Text("go A"), onPressed: () => _router.go('/')),
TextButton(child: Text("push A"), onPressed: () => _router.push('/')),
TextButton(child: Text("go B"), onPressed: () => _router.go('/b')),
TextButton(
child: Text("push B"), onPressed: () => _router.push('/b')),
]));
}
}
class MyHomePageB extends StatelessWidget {
const MyHomePageB({super.key});
@override
Widget build(BuildContext context) {
final st = GoRouterState.of(context);
print("locB: ${st.location}");
return Scaffold(
appBar: AppBar(
title: const Text("B"),
),
body: Column(children: [
TextButton(child: Text("go A"), onPressed: () => _router.go('/')),
TextButton(child: Text("push A"), onPressed: () => _router.push('/')),
TextButton(child: Text("go B"), onPressed: () => _router.go('/b')),
TextButton(
child: Text("push B"), onPressed: () => _router.push('/b')),
]));
}
}Launch, click on pushA or pushB, observe that the shell state doesn't take the pushed route into account.
Metadata
Metadata
Assignees
Labels
No labels