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();`
}
Share:
259
Admin
Author by

Admin

Updated on December 29, 2022

Comments

  • Admin
    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
      Amon C over 2 years
      Could you tell me why are you using the loop inside Future?
    • Gaspard Merten
      Gaspard Merten over 2 years
      Could you give us the entirety of your Future Builder widget?
    • Admin
      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
    Admin over 2 years
    unfortunately also the integration of a Completer with logic on different arrays it blocks the main graphic thread
  • Admin
    Admin almost 2 years
    can you please elaborate how you solved it? which function you used in the field future in the futureBuilder?