Flutter The argument type 'List<dynamic>' can't be assigned to the parameter type 'List<Widget>'

Viewed 2303

this is the error I get and I don't know how to solve it

The argument type 'List' can't be assigned to the parameter type 'List'.

Thank you in advance for help in solving

SOLUTION: blind me found solution in: type 'List<dynamic>' is not a subtype of type 'List<Widget>'

  StreamBuilder<List<ScanResult>>(
                stream: FlutterBlue.instance.scanResults,
                initialData: [],
                builder: (c, snapshot) => ListView(
                  shrinkWrap: true,
                  children: snapshot.data!
                      .map(
                        (r) => ScanResultTile(
                          result: r,
                          onTap: () => Navigator.of(context)
                              .push(MaterialPageRoute(builder: (context) {
                            r.device.connect();
                            return DeviceScreen(device: r.device);
                          })),
                        ),
                      )
                      .toList(),
                ),),
1 Answers

Streambuilder returns a dynamic list so instead of returning ListView, return ListView.builder:

 StreamBuilder<List<ScanResult>>(
                stream: FlutterBlue.instance.scanResults,
                initialData: [],
                builder: (c, snapshot) => ListView(  <------- change this with ListView.builder
                  shrinkWrap: true,
                  children: snapshot.data!
                      .map(
                        (r) => ScanResultTile(
                          result: r,
                          onTap: () => Navigator.of(context)
                              .push(MaterialPageRoute(builder: (context) {
                            r.device.connect();
                            return DeviceScreen(device: r.device);
                          })),
                        ),
                      )
                      .toList(),
                ),),
Related