i have create a page in flutter which display the list of data fetch from firebase, while loading circular progress indicator will show. after the data get fully fetched, the user click the filter icon and it trigger the show bottom sheet model simultaneously behind the bottom sheet the data from
firebase get re fetch with circular indicator unnecessary.
the data should get re fetch only after the user made a change through filter. i need to remove the unnecessary fetching process. i have tried to change the set state method. is there any other approach to remove this duplicate re fetch.
Surya Ns is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Use this logic may help you
bool shouldFetchData = true;
void fetchData() async {
if (shouldFetchData) {
setState(() {
isLoading = true; // Show loading indicator
});
// Fetch data from Firebase
data = await FirebaseService.getData();
setState(() {
isLoading = false; // Hide loading indicator
shouldFetchData = false; // Prevent further unnecessary fetches
});
}
}
void showFilterBottomSheet() {
showModalBottomSheet(
context: context,
builder: (context) {
return FilterBottomSheet(
onFilterChanged: (newFilters) {
// Update the filters and set the flag to fetch data again
filters = newFilters;
shouldFetchData = true;
Navigator.of(context).pop();
fetchData(); // Fetch data again after applying filters
},
);
},
);
}
@override
void initState() {
super.initState();
fetchData();
}
Javroid Breakers is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.