简体   繁体   中英

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

I am developing an android app for database connection.

I got an error when I run the code in Android Studio

Code:

static List<Product> fromMapList(List<Map<String , dynamic>> query)
  {
    List<Product> products = <Product>[];
    for(Map mp in query)
    {
      products.add(fromMap(mp));
    }
    return products;
  }

Error:

Error: The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>'.
 - 'Map' is from 'dart:core'.
      products.add(fromMap(mp));
                           ^

I dont understand what causes the error.

You have defined Map<String, dynamic> type inside List for fromMapList method parameter and while calling fromMapList method you are passing List<Map<dynamic, dynamic>> argument. So you can just change the parameter type to avoid this error.

static List<Product> fromMapList(List<Map<dynamic , dynamic>> query)
  {
     List<Product> products = <Product>[];
     for(Map mp in query)
      {
        products.add(fromMap(mp));
      }
  return products;
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM