class _HomeScreenState extends State<HomeScreen> {
FirebaseFirestore firebaseFirestore = FirebaseFirestore.instance;
late Stream<QuerySnapshot> streamData;
@override
void initState() {
super.initState();
streamData = firebaseFirestore.collection('movie').snapshots();
}
Widget _fetchData(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection('movie').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return LinearProgressIndicator();
}
return _buildBody(context, snapshot.data!.docs);
});
}
Widget _buildBody(BuildContext context, List<DocumentSnapshot> snapshot) {
List<Movie> movies = snapshot.map((d) => Movie.fromSnapshot(d)).toList();
return ListView(children: [
Stack(
children: [CarouselImage(movies: movies), TopBar()],
),
CircleSlider(movies: movies),
BoxSlider(movies: movies)
]);
}
@override
Widget build(BuildContext context) {
return _fetchData(context);
}
}