I am encountering a very bizarre problem with my FutureBuilder on my home screen that only shows up when I've navigated to other pages and then it keeps reloading (I've verified by putting breakpoints on my home screen).
I'm fairly certain this is not how FutureBuilders are supposed to act, or even why it's reloading in a loop only away from my home screen?
CONOPS:
- I load my app
- the FutureBuilder on the home screen works as expected. It receives its futures, builds the app, and that's that
- I navigate to another screen
- the FutureBuilder on my home screen suddenly starts firing again and won't stop
My home screen code, which is a Stateful
widget:
@override
Widget build(BuildContext context) {
generateLayout(); // Assigns padding/spacing based on screen size
return MaterialApp(
title: 'Home Screen',
// This builder is here for routes needing an up-the-tree context
home: Builder(builder: (context) {
Future.delayed(Duration.zero, () {
// Shows disclosure on location usage
return showLocationDisclosureDetermination(context);
});
return Scaffold(
appBar: AppBar(
title: startScreenTitle('Location Alerts'),
),
body: FutureBuilder(
future: initFunctions(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
if (snapshot.hasData) {
return startScreenBody(context);
} else {
return const Center(
child: CircularProgressIndicator(
color: Color(s_darkSalmon),
));
}
}),
);
}),
);
}
My initFunctions()
code:
Future<bool> initFunctions() async {
await sharedPreferencesLookUp(); // Getting Shared Preferences vars
await databaseLookUp(); // Doing a Firestore query
await locationServicesLookUp(); // Getting location services info
return true;
}
And lastly, how I navigate away from the home screen:
return ElevatedButton(
onPressed: () async {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const SpecificScreen()),
);
},
child: Text('Go Right'));