Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Inserting List of strings as list of objects

I need to add items to a Appointment item.

Appointment is a class as follows:

Appointment Appointment({   
String? startTimeZone,   
String? endTimeZone,   
String? recurrenceRule,   
bool isAllDay = false,   
String? notes,   
String? location,   
List<Object>? resourceIds,   
Object? recurrenceId,   
Object? id,   
required DateTime startTime,   
required DateTime endTime,   
String subject = '',   
Color color = Colors.lightBlue,   
List<DateTime>? recurrenceExceptionDates, })

I am inserting Appointment items as follows:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

List<Appointment> appointments = <Appointment>[];
    appointments.add(Appointment(
      startTime: DateTime.now(),
      endTime: DateTime.now().add(const Duration(hours: 1)),
      subject: 'Formación presencial',
      color: Colors.green,
      notes: "Formación presencial",
      location: "Zaragoza",
      resourceIds:  EventObjects(profId: "1",profAvatar: "as",profColor: "dd",profNombre: "ee",eventoColor: "Cc",eventoTipo: "Rr"),

    ),);

But I don´t understand the concept of List of objects, I would like to add as resourcesIds an object from type EventObjects.

class EventObjects{
String? profId;
String? profColor;
String? profNombre;
String? profAvatar;
String? eventoTipo;
String? eventoColor;

// added '?'

  EventObjects({this.profId, this.profColor, this.profAvatar, this.profNombre, this.eventoColor, this.eventoTipo});
// can also add 'required' keyword
}

But I guess this is not the way to do it as the line

resourceIds:  EventObjects(profId: "1",profAvatar: "as",profColor: "dd",profNombre: "ee",eventoColor: "Cc",eventoTipo: "Rr"),

is marked as error

The argument type 'EventObjects' can't be assigned to the parameter type 'List<Object>?'

>Solution :

You are trying to assign here

resourceIds:  EventObjects(profId: "1",profAvatar: "as",profColor: "dd",profNombre: "ee",eventoColor: "Cc",eventoTipo: "Rr"),

a EventObjects instance to a field List<Object>?

What you may want to do is to either declare the resourceIds as Object or EventObjects or make a list literal of resourceIds like this

resourceIds:  [EventObjects(profId: "1",profAvatar: "as",profColor: "dd",profNombre: "ee",eventoColor: "Cc",eventoTipo: "Rr")],

Both will work

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading