简体   繁体   English

我想检索存储在作为数组存储的 firebase 中的数据。 然后我需要从 firebase 获取数组并将其存储在 flutter 列表中

[英]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.

相关问题 如何使用 firebase 数据库存储和检索数组值? - How can i stored and retrieve an array value using firebase database? 如何通过 flutter 中的文档从 firebase 存储中检索数据? - How do i retrieve data from firebase store by document in flutter? 我在数组中遇到问题我从 firebase (firestore) 获取数据,我想显示数据数组我该怎么做? - I face a problem in the array I get the data from firebase (firestore) and I want to show array of data how can i do? 使用 flutter 从 firebase 获取集合列表 - Get list of collection from firebase using flutter 我想使用父节点名称 flutter firebase 数据库访问子节点数据 - i want to access child node data using parent node name flutter firebase data base 如何从 Firebase 实时数据库中获取数据到 Flutter 的列表中? - How to get data from Firebase Realtime Database into list in Flutter? 访问存储在 firebase 实时数据库中的数据 - accessing data which is stored inside firebase real time database 数据存储在单行中,但我想将其一一存储在 Firebase 实时数据库中 - Data Store in single line but I want to store it one by one in Firebase Realtime Database Flutter firebase 检索我的对话列表集合 - Flutter firebase retrieve My Conversations List collection 如何从 firebase 存储中存储的文件中获取 URL? - How to get URL from files stored in firebase Storage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM