Flutter: GetX place multiple pages on the stack - flutter

I use Getx for route management in my Flutter application.
When a certain notification arrives and the app starts from terminated state I want:
launch the / route (launch screen)
go to potm/:match_id route
when user presses back go to match/:match_id route
when user presses back go to home route
Basically I want to have this stack: home -> match/:match_id -> potm:/match_id and then popping from the top will bring me back at home
In the / page initState method I do the following
var matchId = getMatchId();
Get.offToNamed("/home"); // place home on stack and remove /
Get.toNamed("/match/" + matchId); // place /match/:match_id on stack
await Get.toNamed("/potm/" + matchId); // go to /potm/:match_id
this kind of works but in some devices I see a very fast transition from / to /home which I don't want to see
What is the best way to achieve my desired stack here?

Related

How to update state when Navigating back to a page Flutter

i am creating a social media like app, when user clicks on post ,it redirects to a commentpage,in commentspage data is coming from a seperate API,so when go back using Navigator.pop(context), the data in home is not updated, if pressed like button,its not reflecting in ui, but updating in Api,
i wrapped Navigator with setstate but its not reflecting,
Use this on navigator push Navigator.push(context).then((value)=>setState((){}); when it pop the screen it will run the setState
Use this sentence to go to the second page so the function will wait second screen to close
bool result = await Navigator.push(context);
if(result){setState((){});}
when u close the second screen use this sentence Navigator.pop(context, true);
so when u comment has been posted successfully, u will back to screen one and complete the function if result boolean is true, else do nothing.

How to get history of all previous pushed navigation for flutter web/native application?

There is an issue with my navigation and it's parsed value from previous screen for web application.
Actually, I go via Get.toNamed(Routes.VISAS); to next screen and next screen's back button is not working when I reload the web application so I have implemented own back button then try to called Get.back(); or Navigator.of(context).pop(); manually but still not working. so I thought during reload the web app it removes all previous navigation and it's parsed value from previous screen as well and this is a big issue for my web app.
so I was thinking to get rid of this issue , first of all I fetch the navigation history if there is no push screen in stack so I will navigate to my home screen else go back to previous screen().
and 2nd issue : when I parsed value via constructor it remove as well when reload the web application so I Will use SharedPreferences() to resolve this. I know this is not a good approach. Help me out to get navigation history in flutter application.
GOTO NEXT SCREEN :
Get.toNamed(Routes.VISAS);
FOR BACK :
Get.back(); // Not working when I reload the web application
//Navigator.of(context).pop();
From :
TO:

Flutter go_router, how to get the whole current stack of pages?

Meaning if I go from a job screen to a client screen (the client the job was for), to another job screen (another job done for the client) etc, how can I display job > client > job?
And including parameters, so I could display Job 12 > SomeCompany > Job 17.
Sub routes aren't sufficient because the stack can repeat through multiple of the same pages infinitely.
I'm not sure about checking the whole stack , but in case of anybody needed to check if there is a page on the stack , GoRouter has a canPop() method:
/// Returns `true` if there is more than 1 page on the stack. bool canPop() => GoRouter.of(this).canPop();
This isn't possible with go_router. auto_route has an API to check the stack, but go_router shows no search results for stack.
Instead of GoRouter.of like in this answer, you could use the extension method BuildContext#canPop. For example, in my onboarding page, I have this logic to pop if I can, and if not possible (the first time someone launches the app), I replace the page.:
if (context.canPop()) {
context.pop();
} else {
context.replace(Routes.dashboard);
// Or alternatively, allow the user to navigate back to onboarding with:
// context.push(Routes.dashboard);
}

Flutter: push multiple pages on stack

I am using Getx for route management.
When coming from deepLink and the app is terminated, I want the app to launch (with splashscreen) and then go to a specific /match/:match_id route (I have the id in the deepLink).
This works well. The problem is that I want to push below this match page, the home page so that when the user goes back he can go there.
Within the initState of the LaunchScreen widget I am doing
Get.offNamed("/home"); // remove `LaunchScreen` and push `Home`
Get.offNamed("/match/:" + match_id); // push `Match`
This works. However there is some inconsistency with animations. I see for few seconds the Home page and then immediately the Match
I would like to jump directly to Match and the user not even seeing the Home one

How to update screen or state on coming back to route using pop

I want to update a screen on coming back to that screen using Navigator.pop.
E.g. I have Home Screen and Some steps screens (Step1, Step2, Step3, Step4)
Home screen is a stateful widget and shows number of steps completed.
The flow is like
Home => Step1 => Step2 => Step3 => Step4
On any step, on pressing back or pressing close button, it should go back to Home screen and home screen should show updated state of steps completed. So i am navigating to next steps in steps screen using Navigator.popAndPushNamed so that Navigator.pop will go to Home screen.
And using Navigator.pushNamed(context, 'Step1').then in Home screen to update it.
But the problem is .then is called just on Step1 itself because it got popped and if user goes like
Home => Step1 => Step2 => Step3 => Home (using pop)
Home scren will only show Step1 is completed because when going from Step1 to Step2, its .then callback was called and when coming to Home from Step3 using Navigator.pop, no code is being executed and i am unable to update the Home Screen.
I know i can use Navigator.pushNamed(context, 'Home') from steps to go to home screen but it doesn't looks ok (it looks like Home screen was pushed on it instead animation should be like it goes back).
You can use a variable in your previous page which will keep a track, if you are coming from the next page and return a boolean true variable, stating that it has returned from the previous activity. You can use that varible in your init method and if the value of that variable is true you can just fire an event which will return appropriate state.
found the solution using RouteObserver and implemented something like example given in https://api.flutter.dev/flutter/widgets/RouteObserver-class.html
The method i was looking for didPopNext of RouteAware.
Check this, It's Working For Me!
Navigator.of(context).push(route).then((val){
//you can update you data here, when coming back
})