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:
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>?'
3
Answers
You are trying to assign here
a
EventObjects
instance to a fieldList<Object>?
What you may want to do is to either declare the
resourceIds
asObject
orEventObjects
or make a list literal ofresourceIds
like thisBoth will work
Here’s the mistake:
You can do it this way:
And you can assign like this:
Actually, you are inserting a Object not
List<Object>
and your datatype for resourceIds is ofList<Object>?
.You can try using this: