简体   繁体   English

如何在 Flutter 中使用 Firebase firestore 中的数据填充我的 ExpansionTile 小部件

[英]How Can I fill my ExpansionTile widget with data from Firebase firestore in Flutter

I'm trying to do the design shown in the picture Link below.我正在尝试做下面图片链接中显示的设计。 I am getting the data (transportation, plastics) from my Firestore Database and I am able to know which one is in progress or not started yet.我正在从我的 Firestore 数据库中获取数据(运输、塑料),并且我能够知道哪个正在进行或尚未开始。 But I do not know where to start when doing the ExpansionTiles picture但是做ExpansionTiles图片的时候不知道从哪里开始

So far, this is the code that I Currently have.到目前为止,这是我目前拥有的代码。 Can anyone please give me some guidance how to start doing this?谁能给我一些指导如何开始这样做? Sorry I'm a beginner and this may seem a very easy question but I am confused.抱歉,我是初学者,这似乎是一个非常简单的问题,但我很困惑。

 import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class ChallengeScreen extends StatefulWidget {
  const ChallengeScreen({Key? key}) : super(key: key);

  @override
  // ignore: no_logic_in_create_state
  _ChallengeScreenState createState() => _ChallengeScreenState();
}

class _ChallengeScreenState extends State<ChallengeScreen> {
  @override
  void initState() {
    super.initState();
    WidgetsFlutterBinding.ensureInitialized();
  }

  final Query _collectionRef = FirebaseFirestore.instance.collection('modules');

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        const ExpansionTile(
          title: Text('In Progress'),
          children: <Widget>[
            ListTile(title: Text('This is tile number 1')),
          ],
        ),
        const ExpansionTile(
          title: Text('Discover New'),
          children: <Widget>[
            ListTile(title: Text('This is tile number 2')),
          ],
        ),
        const ExpansionTile(
          title: Text('Completed'),
          children: <Widget>[
            ListTile(title: Text('This is tile number 3')),
          ],
        ),
      ],
    );
  }
}

There is my suggestion:有我的建议:

  • 1st, replace your Column by ListView so in case there's overflow it'll avoid error (or wrap Column with SingleChildScrollView ) 1st,用ListView替换你的Column ,这样万一有溢出它会避免错误(或用SingleChildScrollView包装Column
  • 2nd, if the ExpansionTile children's value will change (because you'll have to await data from Firebase) then remove the const 2,如果ExpansionTile孩子的值会改变(因为你必须等待来自 Firebase 的数据)然后删除const
  • 3rd, here is my code suggestion for your ExpansionTile s (I didn't test it though):第三,这是我对您的ExpansionTile的代码建议(虽然我没有测试它):
ExpansionTile(
  title: Text('In Progress'),
  children: [
    // I'll name the data from firestore "datas"
    datas == null
      ? SizedBox.shrink()
      : Container(
          width: MediaQuery.of(context).size.width, 
          height: /* set custom height here */
          child: ListView.builder(
            scrollDirection: Axis.horizontal,
            itemBuilder: (ctx, index) { 
              SizedBox(
                width: /* set custom value */,
                height: /* set custom value */,
                child: Column(children: [
                  Text(/* set value */ ), 
                  Container(
                    width: /* set custom value */,
                    height: /* set custom value */,
                    decoration: BoxDecoration(
                      image: DecorationImage(
                        image: AssetImage(/* set value */),
                        fit: BoxFit.cover
                      ),
                    ),
                  ),
                ]),
              ), 
            }
          ) 
        ),
  ],
) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将检索到的数据从 firebase 放入 Flutter 中的小部件? - How can I put retrieved data from firebase to a widget in Flutter? 如何在 firebase --FLUTTER 的 DATA.TABLE WIDGET 的数据行中显示数据 - How can I display the data inside the Data row of DATA TABLE WIDGET from firebase --FLUTTER Flutter:如何从 Firestore 的 Firebase 存储中获取 URL - Flutter: How Can I Get URL From Firebase Storage In Firestore 我如何从 Firebase FireStore 获取图像到 carouselSlider Flutter - How can i fetch image from Firebase FireStore into carouselSlider Flutter 如何在小部件上显示从 Firebase 到 Flutter 的当前用户数据 - How can I display on a widget the current user data from Firebase to Flutter Flutter:如何在 Firestore 中获取我的数组数据? - Flutter: How can I get my array data in firestore? 我怎样才能只从 Flutter 中的 Firestore 获取我的消息 - How can i get only my messages from firestore in Flutter 如何将来自 Firestore 的用户名添加到 flutter 的应用栏中? - How can i add username from firestore into my appbar in flutter? 如何将 Firestore 集合中的数据绑定到颤动中的 dropdownfromfield? - How can i bind data from firestore collection to a dropdownfromfield in flutter? 如何使用颤振提供程序从 Firestore 获取数据? - How can I use flutter provider to get data from Firestore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM