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

2,428

Solution 1

listMakans = query.docs.map((m) => Makan.fromSnapshot(m.data() as Map<String, dynamic>?)).toList();

Solution 2

Remove ? from

Makan.fromSnapshot(Map<String, dynamic>

This (m.data()!)) is the Object in the error.

Share:
2,428
Osama Mohammed
Author by

Osama Mohammed

Updated on December 29, 2022

Comments

  • Osama Mohammed
    Osama Mohammed over 1 year

    i have encountered this error :

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

    in this line of code :

     listMakans = query.docs.map((m) => Makan.fromSnapshot(m.data()!)).toList();
    

    and here is the code for (Makan.fromSnapshot):

    Makan.fromSnapshot(Map<String, dynamic>? snapshot)
          : id = snapshot!['id'],
            owner = snapshot['owner'],
            category = snapshot['category'],
            hobby = snapshot['hobby'],
            business = snapshot['business'],
            title = snapshot['title'],
            details = snapshot['details'],
            latlng = snapshot['latlng'],
            from = snapshot['from'].toDate(),
            to = snapshot['to'].toDate(),
            created = snapshot['created'].toDate(),
            updated = snapshot['updated'].toDate();
    

    i didn't understand where the Object here?

  • Osama Mohammed
    Osama Mohammed almost 3 years
    but i tried to delete it, and same problem, the code was work without problems, but after upgrade some plugins, i face this problem
  • Huthaifa Muayyad
    Huthaifa Muayyad almost 3 years
    No, go to your factory Makan.fromSnapshot and remove the question mark.
  • Huthaifa Muayyad
    Huthaifa Muayyad almost 3 years
    Removing the question mark from your method should change the error. It could be from someplace else.