I'm trying to set a notification feature on my Flutter app.
My app is made of a top root Navigator, which handles login page or other simple pages, and contains 4 (or 5, given the user rights) tabs, each one having its own Navigator to handle nested routes (e.g. offers, offers/{id}, categories, categories/{id}).
My problem is : how do I pass the top root navigator RouteSettings.arguments to the nested Navigator ?
Concrete exemple : I send a notification promoting a specific offer with a custom message to display on the page, so in the Firebase instance, I will get parameters before pushing the requested route making
Navigator.of(context).pushNamed('offers/specificOffer', OfferPageArguments(1, "hi this is my message"));
The root Navigator will handle this perfectly, but then, will delegate the correct route and arguments to the nested navigator.. So how do you provide those data ?
I thought of replacing the nested Navigator (RouteSettings settings) => onGenerateRoute(settings)
with
(RouteSettings settings) => onGenerateRoute(rootNavigatorSettings)
But this will only work with the first generated route. Then, making NestedNavigator.of(context).pushNamed('/specificOffers', OfferPageArgs(2, "new message")) will not provide the given arguments.
Did someone already faced the same problem or could give me a different way to achieve this ?
Thanks
Related
I'm trying to create an app that has this structure:
I have several questions.
In what router delegate I should use RouteInformationParser? May be in both router delegates? I'd like to keep the authentication router and the nested router as separate as possible.
The same question applies to setNewRoutePath. In what router delegate I should implement it? Again in both?
In general may be this separate states idea is wrong. Should I abandon it and merge AuthPathState and NestedPathState? Please let me know.
You would usually have separate RouterDelegate if you want to include additional Navigator widgets to allow "nested" navigation (for example preserving a BottomNavigationBar which is part of the widget currently shown by the root Navigator while navigating with the nested Navigator).
Therefore for the use case stated here, I would merge those to something like AppPathState.
I am going to build flutter app with Getx.
I followed nested navigator from
https://github.com/jonataslaw/getx/issues/799#issuecomment-730719165
at this example, only shows 1 step sub routes like "/browse".
I need to make another sub routes like "/browse/tabX" and "/browse/tabY"
when click browse button from BottomNavigationBar, It shows tabs (tabX and tabY) on the top. and tabX is default selected.
for the body, it shows automatically their pages.
Also using Get.Named('/browse/tabY') can access to open their page(select second tab and show their body).
Can you help me?
Oh Now I got the answer!
What I make a mistake is I did not use "sub-name".
for example, at initialRoute,
I used '/home/browser' but it should be '/browser' if it is sub-route.
Because the concept is route to subrouter's root and handle by subrouter.
so "initialRoute from root" route to /home first.
and "initialRoute from subroute" route to /browser again!
I use classed variable instead just string so I did not figure this difference out.
I have a typical CRUD operation task: (List Sites, Add Site, ...)
I created a SitesProvider. In the same provider, I added 2 methods for add and edit. I was thinking to use the same provider in the 2 screens (ListSites and AddEditSite)
In the ListSites screen, it works fine. Here is the problem:
I open the AddSite screen by clicking the AddButton in the ListSites screen
Hit submit (did not enter data, simulating error case)
The error gets displayed in the ListSites screen, not in the AddSite screen.
It makes sense. They both use the same provider, both screens are on the stack. It seems that the first one only consumes the state update and displays the error.
I use MultipleProviders approach that wraps the MaterialApp with all providers in the app.
Can we fix that without creating separate providers for each of the 2 screens?
EDIT:
I used provider.removeListener in the ListSites screen right before I open the AddEdit and it shows the error in the correct screen now. I still have to do some other tweaks to get it back to listen after I add. Not efficient I think but it is a step.
I ended up doing that:
Added Another Field in the provider (stateType: list/addedit)
Change the type per the screen I'm currently in
provider.stateType = UIStateType.add_edit;
await Navigator.push(context,
MaterialPageRoute(builder: (context) => AddEditSiteScreen()));
provider.stateType = UIStateType.list;
in build(), I check for the type
sitesProvider = Provider.of(context);
if (sitesProvider.stateType != UIStateType.add_edit) return Container();
So i have seen many navigation functionalities using named routes like popAndPushNamed,popUntil,pushNamedAndRemoveUntil,pushReplacementNamed. I want to know how to use these functionalities with MaterialPageRoute where i dont have my routes named.
For example:
i have a pages
Screen 1
Screen 2
Screen 3
Screen 4
so from Screen 4 i want to popUntil Screen 2 without using names.
i have read posts where i you can name these routes while pushing but i have issues with that because i have to pass arguments and so i want to just use the functionalities wihtout naming my routes. I am a learner so please take it easy on me.
Navigator.of(context).popUntil(ModalRoute.withName("/Page1"));
basically i want to do the above and other functionalities for named routes without using named routes. Thank you.
In your case you need to go from screen 4-->to screen 3--> and stay at screen 2. So this means you need 2 pops, hence do it like this:
count = 0;
Navigator.popUntil(context, (route) {
return count++ == 2;
});
I'm trying to navigate between different screens using named routes.
I'm defining a root-Route (you may call it fallback route(?)), some other routes and an initialRoute, linking to a different screen than the root-Route.
The widget tree seems to load the root-route as well. But why?
TicketsScreen has many Widgets and I don't want them to be loaded beforehand.
BTW: This is only an example. When having multiple routes, it still loads both of the mentioned.
That's because /tasks has a leading /.
The navigation system pushes everything that's there, let me explain.
If you had there routes:
/
/tasks
/tasks/new
navigating to /tasks/new will push all of three.
If you want to keep "single" routes, you should use top level qualifiers. In your case that would be removing the / from /tasks.
This mechanism is useful to push a path and avoid strange pops if, for example,
you navigate to /tasks/new from a shortcut (not from /tasks) and then pop back. Would it be good to pop to the starting point? Would it be better if popping from a new task will lead to the tasks page?
That's a brief explanation of what the navigator tries to do, I guess.