How to change the list of events of dynamic type into my own type in calendar in flutter?

202

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.

Share:
202
Aman Chaudhary
Author by

Aman Chaudhary

Updated on December 23, 2022

Comments

  • Aman Chaudhary
    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 of List<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 is List<EventStore> type and events is List<dynamic> type.
    How do I change it to EventStore type?
    Have a look to this repo github repo

  • Piyush  Chauhan
    Piyush Chauhan over 3 years
    It is recommended to explicitely declare the type of object while declaration as far as possible. It minimizes run time errors related to object types.