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

Bin Yun
Map<String, dynamic> messageInfoMap = {
    "message": message,
    "sendBy": myUserName,
    "ts": lastMessageTs,
    "imgUrl": myProfilePic
  };

and....

Future addMessage(
  String chatRoomId, String messageId, Map messageInfoMap) async {
return FirebaseFirestore.instance
    .collection("chatrooms")
    .doc(chatRoomId)
    .collection("chats")
    .doc(messageId)
    .set(messageInfoMap);

for the last line .set(messageInfoMap), I am getting an error saying "The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>'" I don't see anything wrong, as messageInfoMap should be 'Map<String, dynamic>', but I don't know why I'm getting this error.

h8moss

You have two variables, first, you declared messageInfoMap somewhere (you don't show where but I presume all this code is inside the same class?)

Then, your function takes three arguments, the third argument is also called messageInfoMap, and its type is Map, which of course is the same as Map<dynamic, dynamic>. I presume you are passing the first variable as an argument on the function? If that is the case, you just have to make sure you make the second variable a map of string, dynamic:

Future addMessage(
  String chatRoomId, String messageId, Map<String, dynamic> messageInfoMap) async {
return FirebaseFirestore.instance
    .collection("chatrooms")
    .doc(chatRoomId)
    .collection("chats")
    .doc(messageId)
    .set(messageInfoMap);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Flutter: The argument type '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>'

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

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

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

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

Flutter Dart - the argument type 'String' 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

Flutter Convert FromMap to list The argument type 'Object?' 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>'

error: The argument type 'Null' 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>'

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 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>' after updating the version of the SDK

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

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>'

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

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

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

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

Flutter error: The argument type 'Future<Object?> Function()' can't be assigned to the parameter type 'FutureOr<dynamic> Function(dynamic)'

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

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

How to resolve "The argument type 'Map<String, dynamic>?' can't be assigned " on flutter

flutter error : A value of type 'Object?' can't be assigned to a variable of type 'Map<dynamic, dynamic>'

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