I'm using GetMaterialApp
i.e. GetX
stage management.
The home
widget is a FutureBuilder
that checks user login and shows screens accordingly.
In the builder
of the FutureBuilder
I added a print statement and when I run the app it's being printed more than one time.
Is this fine or do I need to make some changes such that it's called only once?
Is this the behaviour of FutureBuilder
or GetMaterialApp
?
Below is my home
widget code
home: FutureBuilder(
future: isUserLoggedIn(),
builder: (c, r) {
print("LOOK");
print(r.data);
bool isLoggedIn = r.data == null ? false : r.data as bool;
if (isLoggedIn) {
return const DashboardScreen();
}
return const LoginScreen();
},
),
Following is the output printed
I/flutter (29328): LOOK
I/flutter (29328): null
[GETX] Instance "ImageFetcher" has been created
I/flutter (29328): LOOK
I/flutter (29328): true
I/flutter (29328): LOOK
I/flutter (29328): true
CodePudding user response:
that is the behavior of FutureBuilder, you can see some references of this here:
Flutter FutureBuilder gets constantly called
https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html
it is not related to GetX