简体   繁体   中英

Update Field with FieldPath, update doesn't accept FieldPath as parameter - Firebase Flutter

I was trying to delete a FieldValue inside Firebase, but the key had a "/" in it. So my app gave me this exception:

FirebaseException ([cloud_firestore/unknown] Use FieldPath.of() for field names containing '~*/[]'.)

After researching "FieldPath" for a while, I came up with following:

final CollectionReference userTodos = FirebaseFirestore.instance.collection('userTodos');
Future deleteToDo(String key, String listID) async {
    return await userTodos
        .doc(userID)
        .collection('Lists')
        .doc(listID)
        .update(FieldPath([key]), FieldValue.delete());
  }

But for some reason, it gives me this error:

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

I don't understand why because here it says it accepts a String or FieldPath: https://firebase.google.com/docs/reference/js/v8/firebase.firestore.DocumentReference#update

Could someone help me please? Thanks:)

You are referring to the documentation of the JavaScript Firestore client API, while you are using the Dart programming language. That's the source of confusion.

The Dart Firestore client's DocumentReference.update method doesn't accept FieldPath s.

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