Reputation: 891
I have found some posts that address this issue and I have tried to use their solutions without success.
I am new to flutter so I need someone's advice on what to do here.
Here is the error message in the Debug panel:
A build function returned null.
The offending widget is: StreamBuilder<List<Event>>
Build functions must never return null.
To return an empty space that causes the building widget to fill available room, return "Container()". To return an empty space that takes as little room as possible, return "Container(width: 0.0, height: 0.0)".
The relevant error-causing widget was:
StreamBuilder<List<Event>> file:///C:/Users/nkane/AndroidStudioProjects/tonnah/lib/screens/appointment_calendar.dart:166:11
Here is the code starting at line 166:
StreamBuilder(
//stream: _firestoreService.getEventStream(_selectedDay),
stream: _db.collection('agency').doc(globals.agencyId).collection('event')
.where('eventDate', isGreaterThanOrEqualTo: Timestamp.fromDate(_selectedDay))
.snapshots().map((snapshot) => snapshot.docs
.map((document) => Event.fromFirestore(document.data()))
.toList()),
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Event> snapData;
return snapData = snapshot.data;
_eventsStream = snapData;
_eventsMap = convertToMap(snapData);
//_selectedEventsMap = _eventsMap[_selectedDay] ?? [];
return _buildTableCalendar();
}
},
),
How do I fix this? I know I need a "return" but how do I use it?
Upvotes: 1
Views: 85
Reputation: 3278
You just need to return a view while the data is fetching/loading. In this case I've used a CircularProgressIndicator
widget.
StreamBuilder(
stream: ...,
builder: (context, snapshot) {
if(snapshot.hasData){
return build_your_widget;
} else
return CircularProgressIndicator();
}
)
Upvotes: 2