'how is setstate working in the given code
Okay I am following a tutorial and part of the code is listed below. I know how it works but I don't understand why it works. When the user is null, you are supposed to go to the SignInPage which it does. But why does it do that, shouldn't the app go in a loop on this landing page? as in there is a setState method(inside _updateUser method) which runs when the user is null, it updates the state and it should on the same page and do this infinite times. I'm sorry if my question is dumb :).
void _updateUser(FirebaseUser user) {
setState(() {
_user = user;
});
}
@override
Widget build(BuildContext context) {
if (_user == null) {
return SignInPage(
onSignIn: _updateUser,
);
Solution 1:[1]
What happens here is that you are sending _updateUser as a variable to SignInPage instead of calling it in landing page so setState won't be called in the landing page instead it will be triggered in SignInPage assuming the SignInPage calls the function somewhere.
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 | DharmanBot |
