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

Time:01-03

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.

CodePudding user response:

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;
 }
  • Related