I'm using FutureBuilder
on a screen with BottomNavigationBar
. But whenever I click on a different tab and come back, FutureBuilder
reloads everything again. I'm already using AutomaticKeepAliveClientMixin
, I'm having trouble saving getLessons() so I don't have to load it again. Can someone help me?
@override
Widget build(BuildContext context) {
return FutureBuilder<List<Lesson>>(
future: getLessons(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.none) {
} else if (snapshot.connectionState == ConnectionState.waiting) {
} else {
return Container();
}
});
}
This is my getLessons():
Future<List<Lesson>> getLessons() async {
String url = "...";
http.Response response = await http.get(url);
var data = json.decode(response.body);
(...)
return lessons;
}
How can I maintain the state so as not to update?