[英]I want to retrieve data stored in firebase which is stored as an array. then I need to get the array from firebase and store it in a list in flutter
**This is the sample of my database ** sample of database **这是我的数据库示例 ** 数据库示例
I need to fetch those array and stored into a list我需要获取那些数组并存储到列表中
This is the model class that i created for those data这是我为这些数据创建的模型类
> class ContainerItems { String Title, time, daytime, iconName;
>
> ContainerItems({required this.Title,
> required this.iconName,
> required this.time,
> required this.daytime}); }
and please show me how to access each individual items.请告诉我如何访问每个单独的项目。 in the list在列表中
please help请帮忙
well i got the answer..... hope this help others also.好吧,我得到了答案.....希望这也能帮助其他人。
Here todaysmeal is a refactored widget.这里的 todaysmeal 是一个重构的小部件。
class messDiary extends StatefulWidget { messDiary({Key? key}) : super(key: key) {}
// late String whatIsToday = DateFormat('EEEE').format(DateTime.now());
@override State<messDiary> createState() => _messDiaryState(); }
class _messDiaryState extends State<messDiary> { int activeIndex = 0; final carouselController = CarouselController(); String valueChoose = 'Select a day'; var itemName;
final DocumentReference _collectData =
FirebaseFirestore.instance.collection('messdiary').doc('days');
late Stream<DocumentSnapshot> _streamCollect;
@override void initState() {
super.initState();
_streamCollect = _collectData.snapshots(); }
@override Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
return Scaffold(
backgroundColor: const Color(0xFF000000),
appBar: AppBar(
backgroundColor: const Color(0xFF000000),
elevation: 0,
),
bottomNavigationBar: const bottomNavigation(),
body: ListView(
children: [
Column(
children: [
headings(headingText: "Today's meals"),
const SizedBox(
height: 15,
),
StreamBuilder<DocumentSnapshot>(
stream: _streamCollect,
builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if (!snapshot.hasData) {
return const Center(
child: CircularProgressIndicator(),
);
}
final snaps = snapshot.data!;
final sundayMeals = snaps["sunday"]
.map((e) => todaysMeal(
itemName: e['title'],
itemImage: e['image'],
time: e['time'],
dayTime: e['daytime']))
.toList();
final List<Widget> mealsData = [...sundayMeals];
return CarouselSlider(
options: CarouselOptions(
height: height * 0.38,
aspectRatio: 2.0,
autoPlayCurve: Curves.easeInOutQuart,
pauseAutoPlayTouch: true,
enlargeCenterPage: true,
enableInfiniteScroll: false,
initialPage: 2,
autoPlay: true,
onPageChanged: (index, reason) {
setState(() {
activeIndex = index;
});
},
),
items: mealsData,
);
}),
const SizedBox(
height: 15,
),
AnimatedSmoothIndicator(
onDotClicked: animateToSlide,
effect: const ExpandingDotsEffect(
dotWidth: 14,
dotHeight: 14,
activeDotColor: Color(0xFF6A7086),
dotColor: Color(0xFF2B2E3F)),
activeIndex: activeIndex,
count: 4,
),
const SizedBox(
height: 15,
),
const Divider(
color: Color(0xFF6A6C70),
indent: 20,
endIndent: 20,
),
],
),
],
),
); }
void animateToSlide(int index) => carouselController.animateToPage(index); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.