简体   繁体   English

仅当集合在 flutter 中有文档时,如何使小部件可见?

[英]How do i make a widget visible only if the collection has docs in flutter?

I'm using firebase database and i want to show a certain widget if there was docs only.我正在使用 firebase 数据库,如果只有文档,我想显示某个小部件。 i tried this line but it's not the right one.我试过这条线,但它不是正确的。

Visibility(
                  visible: controller.doc.isEmpty(),

Not sure what controller.doc.isEmpty() does but you want the widget to be visible if the doc is not empty.不确定controller.doc.isEmpty()做了什么,但如果文档为空,您希望小部件可见。 So you have to change it to:因此,您必须将其更改为:

Visibility(
  visible: !controller.doc.isEmpty(),
)

Try the following code:试试下面的代码:

Visibility(
  visible: controller.doc.isNotEmpty(),
),

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

相关问题 如何在 Firestore 集合组查询 Flutter 中获取子集合文档 - How to Get Subcollection docs in Firestore Collection Group Query Flutter 如何使用 flutter 从 Firestore 获取子集合? - How do I fetch sub collection from firestore using flutter? Flutter:当小部件没有父/子关系时,如何从小部件 B 调用小部件 A 中的 function? - Flutter: How do I call a function in widget A from widget B when the widgets do not have a parent/child relationship? Flutter Firebase - 在具有多个文档的集合中使用 where 检索数据 - Flutter Firebase - retrieving data using where in a collection with multiple docs 如何获取在 flutter 中具有特定字段值的 Firestore 文档的 DocumentID? - How do I get the DocumentID of a firestore document that has a particular field value in flutter? 如何从也有集合的 firebase 文档创建 Object? - How do I create an Object from a firebase document that also has a collection? 我如何告诉 Flutter 这是一个安全站点? - How do I tell Flutter that it is a safe site? 如何创建 Flutter stream 构建器? - How do I create Flutter stream builder? 如何访问不在树中构建小部件的 dart 文件中的继承小部件? - How do I access my inherited widget in a dart file that doesn't build a widget in the tree? 如何在谷歌地图 flutter 的初始化程序中访问小部件 - How to access widget in an initializer in google maps flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM