【发布时间】:2021-05-30 17:46:55
【问题描述】:
我可以按照以下代码在 Flutter 应用程序中成功创建 listview.builder。
代码
Container(
child: StreamBuilder<QuerySnapshot>(
stream: query2.snapshots(),
builder: (BuildContext context,AsyncSnapshot<QuerySnapshot> snapshot) {
var usernames = snapshot.data.docs.map((e) => e['itemName']);
print("usernames");
print(usernames);
if (snapshot.hasError) {
return Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Text("Loading");
}
return ListView.builder(
itemCount: snapshot.data.docs.length,
itemBuilder: (context, index){
// String itemname =snapshot.data.docs[index]['itemName'] ?? "";
return ListTile(title:Text(snapshot.data.docs[index]['itemName'] ?? ""
),);
});
}
),
)
但我想在大约 5 种不同的 if-else 条件下创建列表视图构建器,但我无法这样做,我试图在 StreamBuilder 上实现这个东西,但无法做到,尽管三元运算符工作,但一次只有两个条件而不是多个条件,我应该如何实现它?
【问题讨论】:
标签: android flutter listview dart flutter-listview