【问题标题】:How to display any Data from Firestore using ternary operator如何使用三元运算符显示 Firestore 中的任何数据
【发布时间】:2020-12-23 00:20:33
【问题描述】:

我试图从 firebase 获取数据,并且我想仅在 firebase 集合中有任何可用数据时才显示 Instagram 图标。我使用以下方法从 firebase 获取数据

StreamBuilder(
        stream: Firestore.instance.collection("aboutpage").snapshots(),
        builder: (context, snapshot) {
          if (!snapshot.hasData) {
            return Container(
              child: Center(
                child: SpinKitThreeBounce(
                  color: Colors.lightBlueAccent,
                  size: 30.0,
                ),
              ),
            );
          } else {
            return Container(
              child: ListView.builder(
                physics: ClampingScrollPhysics(),
                shrinkWrap: true,
                itemCount: snapshot.data.documents.length,
                itemBuilder: (BuildContext context, int index) {
                  DocumentSnapshot aboutpage = snapshot.data.documents[index];
                  return Column(

从 firebase 检索数据时没有问题。问题是当我想显示 Instagram 图标时,如果 firebase 中的数据可用,则使用三元运算符但对我不起作用

"${aboutpage["name"]}" == null 
 ? Container() 
 : IconButton(Icon: Icons.instagram),
   onPressed: (}{}
),

我也尝试过使用"${aboutpage["name"]}".isEmpty,但它对我有用。那么,只有当数据可用且空返回空容器时,我如何才能获取数据?

【问题讨论】:

    标签: firebase flutter dart flutter-layout


    【解决方案1】:

    将条件从"${aboutpage["name"]}" == null 更改为aboutpage is Map && aboutpage["name"] == null

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-12
      • 1970-01-01
      • 2015-07-31
      • 2020-11-25
      • 2020-03-25
      • 2019-03-27
      • 2022-01-04
      • 2020-05-10
      相关资源
      最近更新 更多