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(); }
CodePudding user response:
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
},
);
CodePudding user response:
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()
),