'API data from provider seems to get lost during Navigation
I am a beginner level Flutter developer trying to resolve the issue with the Navigation stack. In the existing app:
- When user logs in to the app, login api call is shooted
- Homescreen is rendered with Navigator.popUntill method
- All the APIs in the providers get shooted and the respective tabs/screens get filled with api data.
Now, I want to include Onboarding screens before Homescreen, so I made below changes:
- Navigator.push method used to include Onboarding screens.
- After onboarding screens are over, user clicks on "To app" button
- On click of "To app" button, the login call is made again
- User is redirected to Homescreen with Navigator.popUntill method.
But now the data from providers is lost as the respective screens do not show any data. I am pretty sure that something is going wrong with the Navigation stack when I use Navigator.push method to add Onboarding screens but I do not have much expertise in Flutter to debug the issue. Need help with restoring the provider data when navigating to Onboarding screens.
Solution 1:[1]
I think that the cause isn't in a navigation stack. Probably you placed Provider widget lower than navigation (MaterialApp).
Try something like that or show your code for better understanding.
Provider(
create: (context) => ClassThatCallsAPI(),
child: MaterialApp(
// Navigator placed here and any route will
// get the same data from provider
// and also can put some
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sergey Lobanov |
