skip to Main Content

So i’m getting the obvious error of undefined name

CloudNote.fromSnapshot(QueryDocumentSnapshot<Map<String, dynamic>> snapshot)
firstName = snapshot.data()[firstNameFieldName] as String;
lastName = snapshot.data()[lastNameFieldName] as String;

I know the painful option of manually adding the field but…..last resort.

Strange that the Firestore Database doesn’t allow you to select all documents in your collection and add fields to all of them.

2

Answers


  1. Chosen as BEST ANSWER
    void addFirstNameLastName(
      {required String ownerUserId,
      required String? firstName,
      required String? lastName}) async {
    try {
      await notes
          .where(
            ownerUserIdFieldName,
            isEqualTo: ownerUserId,
          )
          .get()
          .then((value) => value.docs.forEach((doc) {
                doc.reference.set({
                  firstNameFieldName: '',
                  lastNameFieldName: '',
                }, SetOptions(merge: true));
              }));
    } catch (e) {
      throw (CouldNotGetAllNotesException());
    }}
    

    Adding a - update function in FirebaseCloudStorage class


    Calling the class when button is tapped.


  2. You could try something like this

     Future<void> addFirstNameLastName(
      {required String ownerUserId,
      required String firstName,
      required String lastName}) async {
    try {
      await notes
          .where(
            ownerUserIdFieldName,
            isEqualTo: ownerUserId,
          )
          .get()
          .then((value) => value.docs.forEach((doc) {
                doc.reference.update({
                  firstNameFieldName: firstName,
                  lastNameFieldName: lastName,
                });
              }));
    } catch (e) {
    }}
    

    That’s a good point, I think Firebase/Google are working on that feature. It is a little odd that they have only implemented delete functionality. But try the code above in your FirebaseCloudStorage class. Assign it to a button

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search