'Unable to update Firestore Database with a Map - "Invalid argument: Instance of ‘AppointmentSlot’”

I am running into an issue when I am trying to update my Firestore database with a new updated value for my email field which is part of a List of Maps in my Firestore database.

I am trying to update the email field with a specific email id.

I have included my Firestore collection and the code I am using to update the Firestore document and I have also included the values which the object has with the updated information.

When it tries to run the below code snippet it gives me the error “Invalid argument: Instance of ‘AppointmentSlot’”

Can someone help with why I am getting this error and the way to resolve it? Any help would greatly be appreciated.

My Firestore Collection

Code snippet where I update the document for the date "3-17-2022"

Picture of debugger showing changes I'm trying to update

Model for AppointmentsInfo



Solution 1:[1]

I am wondering if Firestore is having issues to update the data because it does not know anything about my custom object appointmentslots.

Any suggestion on how to resolve the issue? Below is the code snippet of how I am calling it

Future updateAppointment(AppointmentsInfo appointmentsInfo) async {
  try{
    return await appointments.doc(appointmentsInfo.selectedDate).set({
      'appointmentslots' : **appointmentsInfo.appointmentslots**,
      'day' : appointmentsInfo.day,
      'selecteddate' : appointmentsInfo.selectedDate,
    }, SetOptions(merge: true));
  } catch(e){
    print(e.toString());
  }

}

Here is the class that I defined for appointmentsInfo.

class AppointmentSlot {
  final String email;
  final String slot;

  AppointmentSlot({ required this.email, required this.slot });
}

class AppointmentsInfo {
  final List<**AppointmentSlot**> appointmentslots;
  final String day;
  final String selectedDate;

  AppointmentsInfo({ required this.appointmentslots, required this.day, required this.selectedDate });

 // AppointmentsInfo({ required this.day });
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ronit Dasgupta