i have a future builder that get data from firestore. the data is coming but futurebuilder is not awaiting it the first time. when i hot reload it works
firestore code below
Future<List<ScheduleWithCourse>> getcourse() async {
List<ScheduleWithCourse> s = new List<ScheduleWithCourse>();
await appliedCoursesCollication
.where("uid", isEqualTo: uid)
.getDocuments()
.then((doc) {
doc.documents.forEach((f) async {
await scheduleCollection
.where("courseId", isEqualTo: f.data['courseId'])
.getDocuments()
.then((doc) {
doc.documents.forEach((d) {
s.add(ScheduleWithCourse(
tag: d.data['tag'],
course: Map.from(d.data['course']),
time: d.data['time'],
dep: d.data['dep'],
dayOfWeek: d.data['dayOfWeek']));
});
});
});
});
return s;
}
Future builder code
Future<List<ScheduleWithCourse>> _course;
@override
void initState() {
super.initState();
_course = DatabaseService().getcourse();
}
FutureBuilder<List<ScheduleWithCourse>>(
future: _course,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Loading();
} else {
print(snapshot.data.length);
return CarouselSlider(
autoPlay: false,
enlargeCenterPage: true,
aspectRatio: 2.0,
reverse: false,
height:
MediaQuery.of(context).size.height /
4,
viewportFraction: 0.9,
onPageChanged: (index) {},
enableInfiniteScroll: false,
items: snapshot.data.map((f) {
return Builder(
builder: (BuildContext context) {
return Sschedule(schedule: f);
},
);
}).toList(),
);
}
}),
when i remove the initstate it only displays the data for a second and then it disappears