[英]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:有我的建议:
Column
by ListView
so in case there's overflow it'll avoid error (or wrap Column
with SingleChildScrollView
) 1st,用ListView
替换你的Column
,这样万一有溢出它会避免错误(或用SingleChildScrollView
包装Column
)ExpansionTile
children's value will change (because you'll have to await data from Firebase) then remove the const 2,如果ExpansionTile
孩子的值会改变(因为你必须等待来自 Firebase 的数据)然后删除constExpansionTile
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.