How to change the list of events of dynamic type into my own type in calendar in flutter?
You can cast Lists
in Dart like so:
List<dynamic> data = [1, 2, 3, 4]
List<int> dataAsInts = data.cast<int>();
For more information, have a look at the cast() method in the docs.
Aman Chaudhary
Updated on December 23, 2022Comments
-
Aman Chaudhary over 1 year
I am using the table calendar for storing the events in the list. The default list is of
List<dynamic>
type but what I want is to store the events in another type list which is ofList<EventStore>
type. As I change the dynamic to EventStore type, everything goes well.
And I did it like this,
Map<DateTime, List<EventStore>> _events;
But when selecting particular date, it gives the error like,
type 'List<dynamic>' is not a subtype of type 'List<EventStore>'
For showing the list of events for the selected day, I have done this,
onDaySelected: (date, events) { setState(() { _selectedEvents = events; }); },
whereas
_selectedEvents
isList<EventStore>
type andevents
isList<dynamic>
type.
How do I change it toEventStore
type?
Have a look to this repo github repo -
Piyush Chauhan over 3 yearsIt is recommended to explicitely declare the type of object while declaration as far as possible. It minimizes run time errors related to object types.