The argument type 'Iterable<Map<String, dynamic>>' can't be assigned to the parameter type 'List<Map<String, dynamic>>'

al246

I have the below function to take List data from API call and populate pop-up metadata with the first 5 instances of key/value pairs.

   var mappedList = boards.boards!.take(5).toList(); 


   // now, from the list above, I map each result into a key-value pair

    var mappedValues = mappedList.map((m) => { 'headsign': m.getString('headsign'), 'time': m.getString('time') });

   // this list will look like:
   // [{ headsign: 'value1', title: 'title1'}, { headsign: 'value2', title: 'value2' }]


   // Now moving mappedValues list to showDialog
   String title = ("Title Test");

   _DropDownList(mappedValues, title);
   });
  }


  Future<void> _DropDownList(List<Map<String, dynamic>> values, String title) async {
         var test1 = ListBody(
              ...

I receive the error

    The argument type 'Iterable<Map<String, dynamic>>' can't be assigned to the parameter type 'List<Map<String, dynamic>>'

on the line

     _DropDownList(mappedValues, title); //(on 'mappedValues')

This error links to

   var mappedValues = mappedList.map((m) =>

And the error is with the map section of the function. I have tried casting as etc but can't get it to work or go through as a List<Map<String, dynamic>>

Thanks

Update

If I change to iterable like so I get the error The operator '[]' isn't defined for the type 'Iterable<Map<String, dynamic>>'. on [index] where highlighted below

Future<void> _DropDownList(Iterable<Map<String, dynamic>> values, String title) async {
         var test1 = ListBody(
              children: List.generate(
                values.length, (index) {
   *[index]*                return Text(values[index]['headsign']);
                }
              ),
            );

Thanks

Ivo Beckers

You can easily change an Iterable to a list by calling toList() so just change

var mappedValues = mappedList.map((m) => { 'headsign': m.getString('headsign'), 'time': m.getString('time') });

to

var mappedValues = mappedList.map((m) => { 'headsign': m.getString('headsign'), 'time': m.getString('time') }).toList();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>'. error showing in flutter

The argument type 'Map<String, dynamic> Function()' can't be assigned to the parameter type 'Map<String, dynamic>'

Flutter Convert FromMap to list The argument type 'Object?' can't be assigned to the parameter type 'Map<String, dynamic>'

Flutter: The argument type 'dynamic' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'dynamic' can't be assigned to the parameter type 'Map<String, dynamic>' from Lint vs Pedantic

The argument type 'dynamic' can't be assigned to the parameter type 'Map<String, dynamic>'

Flutter Dart - the argument type 'String' can't be assigned to the parameter type 'Map<String,dynamic>'

The argument type 'Set<String>' can't be assigned to the parameter type 'Map<String, dynamic>'

error using riverpod to The argument type 'String' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>' after updating the version of the SDK

Flutter-Firestore "The argument type 'Map<String, dynamic> Function()' can't be assigned to the parameter type 'Map<String, dynamic>"

Flutter: The argument type 'HomePage Function(BuildContext, Map<String, dynamic>)' can't be assigned to the parameter type

The argument type 'Object' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'CollectionReference<Object?>' can't be assigned to the parameter type 'Query<Map<String, dynamic>>'. (Documentation)

JSON Serialization Issue: The argument type 'Tracks' can't be assigned to the parameter type 'Map<String, dynamic>'

error: The argument type 'Null' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'Stream<DocumentSnapshot<Map<String, dynamic>>>' can't be assigned to the parameter type 'Stream<DocumentSnapshot<TaskItems>>?'

The argument type 'List<Series<dynamic, dynamic>>' can't be assigned to the parameter type 'List<Series<dynamic, String>>

Flutter : Facing an error like - The argument type 'Map<String, dynamic>?' can't be assigned to the parameter type 'Map<String, Object?>'

Argument 'Set<Future<DocumentReference<Map<String, dynamic>>>> Function(String)' can't be assigned to parameter type 'void Function(String, dynamic)'

The argument type 'Future<dynamic>' can't be assigned to the parameter type 'String'

The argument type 'MaterialPageRoute<dynamic>' can't be assigned to the parameter type 'String'

Error: The argument type 'List<Series<Sales, String>>?' can't be assigned to the parameter type 'List<Series<dynamic, String>>'

Flutter Error: The argument type 'List<dynamic>' can't be assigned to the parameter type 'Iterable<Future<dynamic>>'

The argument type 'List<Iterable<DropdownMenuItem<int>>>' can't be assigned to the parameter type 'List<DropdownMenuItem<dynamic>>'

A value of type 'List<Map<String, dynamic>>' can't be assigned to a variable of type 'List<ProjectBoxes>'

Set<Map<String, dynamic>>' can't be assigned to the parameter type 'Map<String, dynamic> error in Flutter when writing to Firestore

The argument type 'Object?' can't be assigned to the parameter type 'Map<dynamic, dynamic>'. GetX