-
-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nested routers #4
Comments
We would really like to do this: class MyApp extends StatelessWidget {
final _beamerKey = GlobalKey<BeamerState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Beamer(
key: _beamerKey,
routerDelegate:
BeamerRouterDelegate(initialLocation: _beamLocations[0]),
routeInformationParser: BeamerRouteInformationParser(
beamLocations: _beamLocations,
),
),
bottomNavigationBar: BottomNavigationBarWidget(
beamerKey: _beamerKey,
),
),
);
}
} but then this inner router cannot parse incoming url. We need a "dummy" router just to parse url and pass it down to "main" router that's somewhere inside app. Like this. I will wait for a possible workaround for this and will not implement the outer router yet, because this snippet works fine for every situation (including updating the url correctly) except parsing incoming url. |
it definitely goes in v0.9.0. |
Thank you all for great support in the above comment, but it will not land in BUT worry not... the date still stands; by the end of this week. And. maybe even cooler, it will land in |
ok, so ab9e53d was done for now. It would go something like this, specifically for bottom navigation bar: class MyApp extends StatelessWidget {
final _beamerKey = GlobalKey<BeamerState>();
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routeInformationParser: BeamerRouteInformationParser(),
routerDelegate: RootRouterDelegate(
homeBuilder: (context, uri) => Scaffold(
body: Beamer(
key: _beamerKey,
beamLocations: _beamLocations,
),
bottomNavigationBar: BottomNavigationBarWidget(
beamerKey: _beamerKey,
),
),
),
);
}
} I need to test it some more before releasing. Probably tomorrow night will be ready enough. (edit: it will take some more time) |
how can I do something like this? class MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp.router(
debugShowCheckedModeBanner: false,
routeInformationParser: BeamerRouteInformationParser(),
routerDelegate: RootRouterDelegate(
homeBuilder: (context, uri) => Scaffold(
body: Row(
children: [
Expanded(
flex: 1,
child: ListView(
children: [
ListTile(
title: Text('Home'),
onTap: () => context.beamToNamed('/home'),
),
ListTile(
title: Text('Articles'),
onTap: () => context.beamToNamed('/articles'),
),
ListTile(
title: Text('Books'),
onTap: () => context.beamToNamed('/books'),
),
],
),
),
Expanded(
flex: 3,
child: Container(
color: Colors.blueAccent,
padding: const EdgeInsets.all(32.0),
child: Beamer(
key: _beamerKey,
beamLocations: [
HomeLocation(),
ArticlesLocation(),
BooksLocation(),
],
),
),
),
],
),
),
),
);
}
} I'm getting some errors,
tried to wrap but did not work, I'm using the nested-router branch |
@talski thanks for trying it out so soon 😃 Beamer and the place where you are using it are currently at the same level in Widget tree so you need to do it via the key. This should work (I changed just your class MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp.router(
debugShowCheckedModeBanner: false,
routeInformationParser: BeamerRouteInformationParser(),
routerDelegate: RootRouterDelegate(
homeBuilder: (context, uri) => Scaffold(
body: Row(
children: [
Expanded(
flex: 1,
child: ListView(
children: [
ListTile(
title: Text('Home'),
onTap: () => _beamerKey.currentState.routerDelegate.beamToNamed('/home'),
),
ListTile(
title: Text('Articles'),
onTap: () => _beamerKey.currentState.routerDelegate.beamToNamed('/articles'),
),
ListTile(
title: Text('Books'),
onTap: () => _beamerKey.currentState.routerDelegate.beamToNamed('/books'),
),
],
),
),
Expanded(
flex: 3,
child: Container(
color: Colors.blueAccent,
padding: const EdgeInsets.all(32.0),
child: Beamer(
key: _beamerKey,
beamLocations: [
HomeLocation(),
ArticlesLocation(),
BooksLocation(),
],
),
),
),
],
),
),
),
);
}
} |
I get the same error message, I have pretty much the same implementation as @talski but with an
|
@tomosullivan8 Hi! |
@talski, @tomosullivan8 Let me know if this works for you. You can let us know on beamer's Discord also: https://discord.gg/8hDJ7tP5Mz |
Just saw, you beat me to the reply! Will try it now, thanks. Is there a way to push over the top of the RootRouteDelegate? An example would be like the following, the 'Home', 'About' and 'Contact' would be nested under the Website, but you can push the page to 'Login' and 'Store' over the 'Website':
The issue I've been having is getting the url to update with the inner router instead of using the root. |
@tomosullivan8 yeah, this is definitely an use-case I have in mind to implement soon, but it's impossible currently :( On one hand, I wanted this homeBuilder because it's easy and covers most use-cases, but on the other hand it would be more natural for RootRouterDelegate to also accept BeamLocations. I plan to enable both |
I'll take a look at the Just an FYI, there is a typo in the |
Oh... well, it really shows that it's a working version 😆 You can make a PR to fix that at least :) @tomosullivan8 If you want to make a contribution to that |
Well, well, well,... |
https://gist.github.com/johnpryan/bbca91e23bbb4d39247fa922533be7c9
The text was updated successfully, but these errors were encountered: