_MapStream<QuerySnapshot<Map<String, dynamic>>, List<Event>>' is not a subtype of type 'Map<DateTime, List<dynamic>>

Viewed 380

I don't understand this error message:

type '_MapStream<QuerySnapshot<Map<String, dynamic>>, List>' is not a subtype of type 'Map<DateTime, List>'

I have looked for the meaning of _MapStream but have not found any definition. I have seen it mentioned in other posts here.

I think I need to convert from Map<DateTime,List> type to _MapStream<QuerySnapshot<Map<String, dynamic>>, List> but I don't know what this type is.

I am getting the error in this code segment when I try to add the _eventsStream to the streamController:

    var _eventsStream;

    void _onDaySelected(DateTime day, List events, List holidays) {
        _eventsStream = _firestoreService.getEventStream(day);
        setState(() {
          _streamController.add(_eventsStream);  **<<<<< Error Here**
          //_selectedEvents = _eventsStream;
        });
      }

_eventsStream is populated in the first line and here is the _firestoreService.getEventStream(day) method that is used to populate it:

  Stream<List<Event>> getEventStream(DateTime dateTime) {
    return _db.collection('agency').doc(globals.agencyId).collection('event')
        .where('eventDate', isGreaterThanOrEqualTo: Timestamp.fromDate(dateTime))
        .snapshots().map((snapshot) => snapshot.docs
        .map((document) => Event.fromFirestore(document.data()))
        .toList());
  }

Here is the definition of the Event data structure for the firebase document. This data will be in the record returned from the _firestoreService.getEventStream method above:

class Event {
  final String eventName;
  final DateTime eventStartTime;
  final String eventDuration;
  final DateTime eventDate;
  final String eventDescription;
  final String agentId;
  final String agencyId;

So please help me understand the error message. Should I change the type returned from _firestoreService.getEventStream()? How do I convert from what is returned to what I need? Should I declare _eventsStream as something other than a var? Thanks.

0 Answers
Related