Reputation: 3
I am writing an appendix with a class schedule. I need to display information on cards. at the moment, I get the same result from the database.
body.dart
child: StreamBuilder(
stream: Firestore.instance.collection('lessons').snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
return GridView.builder(
itemCount: snapshot.data.documents.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
mainAxisSpacing: 20,
childAspectRatio: 2.55),
itemBuilder: (context, index) {
return LessonBundelCard(
lesson: snapshot.data.documents,
press: () {},
);
},
);
}),
))
],
);
}
}
1.what type of data should be in lesson? 2.i don't understand what type i need to use
**lesson_bundel_cart.dart**
class LessonBundelCard extends StatelessWidget {
final LessonBundelCard lesson;
final Function press;
Upvotes: 0
Views: 36
Reputation: 26
You should use the type LessonBundelCard for the field lesson. I think you should add fromJson method inside your model class (LessonBundelCard), and then use that to get the required lesson from Firestore.
So, after adding fromJson method, you should use:
return LessonBundelCard(
lesson: LessonBundelCard.fromJson(snapshot.data.documents[index].data),
press: () {},
);
Please check out this documentation for details regarding use of fromJson: https://flutter.dev/docs/development/data-and-backend/json
Also, you should use different names for the model and the stateless widget.
Upvotes: 1