I have been trying to make a simple flutter app, have implemented the login logic.
void _saveForm() async {
final loginDetails = Provider.of<Login>(context);
final isValid = _form.currentState.validate();
if (!isValid) {
return;
}
_form.currentState.save();
loginDetails.isLoggingIn();
await loginDetails.logIn(_loginDetails);
if (loginDetails.getIsLoggedIn()) {
print("Changing page");
Navigator.of(context).pushReplacementNamed(ActivityScreen.routeName);
}
}
This will simply navigate to different page. Now what i want is, if it is logged in, i could use the
loginDetails.getIsLoggedIn()
in my another Provider class to start fetching some data.
I tried using Provider.of<Login>(context);
but context was not found.
If it's not possible, where should I call for the function in the provider to fetch the data, and since i got a auth token by logging in which i am saving in Login
provider, do i have to call the provider of Login to get the auth token and pass everytime with the request.
Is there someting like interceptor in Provider
.
Thanks.