Stuck Loader in FutureBuilder
259
Solved with a Future and compute.
In the detail:
Future<List<CustomObject>> _retrieveCustomObjects() async {
SourceData data = SourceData(CustomSourceData());
return compute(getFilteredClients, data);
}
List<CustomObject> computeCustomObject(SourceData data) {
List<CustomObject> list = [];
// expensive logic on data, not only network call
return list;
}
class LoremIpsumClass {
// use where you need `List<CustomObject> value = await _retrieveFilteredClient();`
}
Author by
Admin
Updated on December 29, 2022Comments
-
Admin 11 months
I'm new of Flutter and Dart in general, I'm trying to do a expansive computation during the loading of the page but the loader is stuck when I try to do something like this:
body: Center( child:FutureBuilder( future: _lorem() builder: (context, snapshot) { if (snapshot.connectionState != ConnectionState.done){ print("loader"); return Center( child: CircularProgressIndicator( backgroundColor: Theme.of(context).primaryColor) ); }
[...]
Future<void> _lorem() async { //there is not a request to service, there is a more than one filter on map and some lists. I set the for loop for example of a local computation return Future(() { for (int i = 0; i < 50000; i++){ print(i); } } ); }
-
Amon C over 2 yearsCould you tell me why are you using the loop inside Future?
-
Gaspard Merten over 2 yearsCould you give us the entirety of your Future Builder widget?
-
Admin over 2 years@AmonChowdhury the view is a summary with some charts and I thought to insert the computation in a Future in order to show a loader during it, but if there is a different way to have that result I will integrate
-
-
Admin over 2 yearsunfortunately also the integration of a Completer with logic on different arrays it blocks the main graphic thread
-
Admin almost 2 yearscan you please elaborate how you solved it? which function you used in the field
future
in thefutureBuilder
?