skip to Main Content

The argument type ‘List<Future>’ can’t be assigned to the parameter type ‘List’

return SizedBox( width: screenSize.width, height: screenSize.height, child: Stack( alignment: Alignment.topLeft, children: listOfWidgets) );

listOfWidgets for example 10 widgets, each widget having one isolate and one compute which are running following function

String Calculate(int num){ int sum=num+num; return sum.toString(); }

2

Answers


  1. in each widget i am planing to use 10 isolates. how it is possible to
    use 10 isolates with one future builder?

    you can try Future.wait

    Future<String> foo;
    Future<int> bar;
    FutureBuilder(
      future: Future.wait([bar, foo]), // here your future function
      builder: (context, AsyncSnapshot<List<dynamic>> snapshot) {
        snapshot.data[0]; //bar
        snapshot.data[1]; //foo
      },
    );
    
    Login or Signup to reply.
  2. try this:

    Stack(
      children: listOfWidgets.map(
        (future) => FutureBuilder<Widget>(
          future: future,
          builder: (context, snapshot) {
            if (snapshot.connectionState != ConnectionState.done) {
              return const CircularProgressIndicator();
            }
            if (snapshot.hasError || !snapshot.hasData) {
              return const Text('something went wrong');
            }
            return snapshot.data!;
          }
        ),
      ).toList()
    ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search