I have a home icon in the navbar whenever the user will click on it, It will take the user to the Home Page. In the Home Page, there are few form fields that I don't want to change when coming back to the Home Page from the navbar Home icon. The following is the code that I am using:
back_to_home(){
this.navCtrl.push( HomePage )
}
By using the above, state is refreshed and changes. Is there way to change the state without refreshing the state?
Related
I have 3 pages - HomePage, FirstPage, SecondPage. HomePage contains a futureBuilder which will fetch data from Server and display it in the HomePage. From HomePage I can navigate to FirstPage (using Navigator.push()) and from there to SecondPage. In the SecondPage I am sending some new data to server. A progress indicator will be shown while sending the data. Now if I press back button two times I will reach the HomePage back. But now the data in HomePage is the same as before. i.e, The data is not updated in the HomePage even if the data is updated in the server. I have button in HomePage which onTap will call setState() and then the Data will be Updated.
But I want the data of HomePage to be updated just after the data is sent from the second page. i.e, from second page we will first show a progress indicator, then we will send data to server, then we will update the data of home page in some way, then only we will stop the progress indicator.So if then we tap back button and return to HomePage, Home page should show the updated data. I don't want to call setState() after clicking back button to home page because it will cause to show a progress indicator(a delay in fetching updated data) again.
Is there any method to do this? Or is there any way to call the setState() method of HomePage from the secondPage ?
Use flutter provider package. Fetch data from Server using global variable. After send the data to server use ChangeNotifier()
function. (Notes: learn about provider package)
I have a problem with my Here Maps Navigation. I can start the navigation on my flutter app but every time I open another page on the app and come back to the navigation page, it restarts the navigation. It tries to get the current location again, takes a lot of time to do that, and shows the default "invalid" map page. I want the navigation to save it's current state even if I change the view to another page on my app and come back to navigating. Is there a way to do this? Am I missing something here?
I finally found a way to solve it by saving the state of my Flutter pages. I used the PageView widget for the main.dart's scaffold body and AutomaticKeepAliveClientMixin on the pages I wanted to save the states of. You can check this YouTube video for how to implement this: https://www.youtube.com/watch?v=fGe45NikVqE
I have multiple screens and I'm using named routes in flutter using getx package.
The problem I'm facing is I'm able to navigate to any other screen when tapped on push notification, but when I go back from that screen my app closes.
But expected outcome is when navigating back I should go to home screen and app should not close.
Please help
Try using the following when back button is pressed:
Navigator.popAndPushNamed(context, '/homeScreen')
I want to take confirmation from user before leaving the app, ideally when clicked on default system back navigation button and at time my navigation stack is empty.
Suppose I am on my homepage after login, and when I try to go back instead of returning me to login page it should show a pop up dialog. And based on the selection either close the app or leave it open.
wrap your home screen widget with WillPopScope widget and inside onWillPop callback write show your dialog and take action based on user's choice
Is there anyway to check route name of last screen after pop? When application start and land on home screen, there are several widgets like view profile, product carousel and so on.
Scenario: User navigate into product listing page, then detail page, click purchase and perform actions. After user purchased, shows purchased successful screen, call Navigator.of(context).popUntil(routeName) back to home screen.
What I want to achieve: After land in home screen, programmatically call api to refresh my balance. Route Observer able to detect navigation back to home screen with didPopNext() method. But this is called no matter it pop from which screen. Therefore the api will repeatedly called which is not ideal. How do I know it was pop from purchased successful screen instead of product listing screen?
Grateful on any helps and hints!
If you where using pop() then you have an option to return some data to previous route but since you are using popUntil() you won't be able to do this. So I think you should clear every route and push home route again from purchased successful page using either pushAndRemoveUntil() or pushNamedAndRemoveUntil(). That means you can now pass an argument to home screen by which you can decide whether to call the API or not.
Navigator.of(context).pushNamedAndRemoveUntil(
'/',
(Route<dynamic> route) => false,
arguments: []
);
Another option would be to figure out a way to return data using popUntil(), Something like this, maybe?