title: Flutter - Is there a way to populate events from my API to TableCalendar's 'events' attribute
body: <p>I've spent ages looking through as many stackoverflow questions to find a solution but I'm all out of ideas. Essentially I'm loading in data from my API and it returns a list of type Event. Below shows the structure:</p>
  
  <pre><code>class Event{
    final int eventId;
    final String eventDate;
    final String eventName;
    final String eventDescription;
  
    Event.fromJSON(Map&lt;String, dynamic&gt; json) :
        eventId = json['eventId'],
        eventDate = json['eventDate'],
        eventName = json['eventName'],
        eventDescription = json['eventDescription'];
  }
  </code></pre>
  
  <p>The async method in which it retrieves it is below:</p>
  
  <pre><code> Future&lt;List&lt;Event&gt;&gt; fetchMonthEvents(String month) async {
      List&lt;Event&gt; eventList;
      final response =
          await http.get(/*MY_API_URL*/);
  
        if (response.statusCode == 200) {
          final List parsedList = json.decode(response.body);
          eventList = parsedList.map((val) =&gt; Event.fromJSON(val)).toList();
          return eventList;
        } else {
          throw Exception('Failed to load post');
        }
    }
  </code></pre>
  
  <p>And now the problem...</p>
  
  <pre><code>class _HomePageState extends State&lt;HomePage&gt; {
    CalendarController _calendarController;
    DateTime daySelected;
  
    Map&lt;DateTime, List&gt; _events;
    List _selectedEvents;
  
    List&lt;Event&gt; _eventList = &lt;Event&gt; [];
    List _dates;
    final _selectedDay = DateTime.now();
  
    @override
    initState() {
      super.initState();
      this.daySelected = DateTime.now();
      _fetchList();
      _calendarController = CalendarController();
  
    }
  
  Future _fetchList() async {
      _eventList = await fetchMonthEvents('2019-10');
                 // below is processing the of _eventList so events are mapped according the date
      for(Event e in _eventList){
        _dates.add(e.eventDate);
      }
      _dates.toSet().toList();
      Map&lt;DateTime, List&gt; eventsParsed = {};
      for(var i=0; i&lt;_dates.length; i++){
        List singleDayEvents = _eventList.where((e) =&gt; e.eventDate.contains(_dates[i])).toList();
        eventsParsed[DateTime.parse(_dates[i])] = singleDayEvents;
      }
      _events = eventsParsed;
      _selectedEvents = _events[_selectedDay] ?? [];
  
      setState(() { //repeated code in a desperate attempt to make it work
        _events = eventsParsed;
        _selectedEvents = eventsParsed[_selectedDay] ?? [];
     });
    }
  ...
  </code></pre>
  
  <p>I continue to get errors all because _events is null. I assume this is due to the asynchronous nature of the Future object (still new to this framework). I've attempted using .then() function and streams but no luck. I've tried a FutureBuilder, however unlike other questions asked, the events attribute of the TableCalendar widget returns a <code>Map&lt;DateTime, List&lt;dynamic&gt;&gt;</code>.</p>
  
  <p>Essentially all I want is for the data returned from the API to be used in populating events in the calendar. I'm open to any ideas to get this to work. I've inserted the call to the async function in initState() since the data is required to load the calendar with it.</p>
  
  <p>I'm open to any and every suggestion, quite desperate at this point since I have a deadline for this. Any help will be much appreciated!</p>