0

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(); }
Rizwan Ahmed
  • 1,272
  • 2
  • 16
  • 27
  • can you include more sample data. the issue is you are getting future widget. Find more about [/minimal-reproducible-example](https://stackoverflow.com/help/minimal-reproducible-example) – Md. Yeasin Sheikh Jan 30 '23 at 15:14
  • the error speaks for itself, you don't have list of widgets, you have list of `Future`. you need to use `FutureBuilder` for each widget. `Stack` -> `FutureBuilder` -> `Widget` – Hydra Jan 30 '23 at 15:34
  • @Hydra in each widget i am planing to use 10 isolates. how it is possible to use 10 isolates with one future builder? – Rizwan Ahmed Jan 30 '23 at 15:40
  • Does this answer your question? [What is a Future and how do I use it?](https://stackoverflow.com/questions/63017280/what-is-a-future-and-how-do-i-use-it) – nvoigt Jan 30 '23 at 15:51
  • @RizwanAhmed no you need to use `FutureBuilder` for each item in your list, meaning you need to map your list to List of `FutureBuilder` – Hydra Jan 30 '23 at 16:10

2 Answers2

0

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
  },
);
pmatatias
  • 3,491
  • 3
  • 10
  • 30
  • I follow your example but facing null value. AsyncSnapshot>(ConnectionState.waiting, null, null, null) FutureBuilder( future: Future.wait( [crossProduct, normalAngle, tangentAngle, normAndTangDiff]), // here your future function builder: (context, AsyncSnapshot> snapshot) { – Rizwan Ahmed Jan 30 '23 at 19:00
0

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()
),
Hydra
  • 550
  • 2
  • 6