Merge pull request #1763 from GetStream/fix/docs-go-router

fix(doc): update the use of GoRouter in the guides
This commit is contained in:
Deven Joshi
2023-11-03 17:29:14 +05:30
committed by GitHub
@@ -489,47 +489,51 @@ class _MyAppState extends State<MyApp> {
late final _router = GoRouter( late final _router = GoRouter(
initialLocation: '/', initialLocation: '/',
navigatorBuilder: (context, state, child) {
if (state.location.startsWith('/chat')) {
wasPreviousRouteChat = true;
return StreamChat(
client: _client,
child: ChatSetup(client: _client, child: child),
);
} else {
if (wasPreviousRouteChat) {
wasPreviousRouteChat = false;
return StreamChat(
client: _client,
child: child,
);
} else {
return child;
}
}
},
routes: [ routes: [
GoRoute( ShellRoute(
path: '/', builder: (context, state, child) {
builder: (context, state) => const HomeScreen(), if (state.uri.host.startsWith('/chat')) {
wasPreviousRouteChat = true;
return StreamChat(
client: _client,
child: ChatSetup(client: _client, child: child),
);
} else {
if (wasPreviousRouteChat) {
wasPreviousRouteChat = false;
return StreamChat(
client: _client,
child: child,
);
} else {
return child;
}
}
},
routes: [ routes: [
GoRoute( GoRoute(
path: 'settings', path: '/',
builder: (context, state) => const SettingsPage(), builder: (context, state) => const HomeScreen(),
),
GoRoute(
path: 'chat',
builder: (context, state) => const ChannelListPage(),
routes: [ routes: [
GoRoute( GoRoute(
path: 'channel', path: 'settings',
builder: (context, state) { builder: (context, state) => const SettingsPage(),
final channel = state.extra as Channel; ),
return StreamChannel( GoRoute(
channel: channel, path: 'chat',
child: const ChannelPage(), builder: (context, state) => const ChannelListPage(),
); routes: [
}, GoRoute(
path: 'channel',
builder: (context, state) {
final channel = state.extra as Channel;
return StreamChannel(
channel: channel,
child: const ChannelPage(),
);
},
),
],
), ),
], ],
), ),