【问题标题】:The argument type 'AsyncSnapshot<DocumentSnapshot<Object>>' can't be assigned to the parameter type 'DocumentSnapshot<Object>'参数类型“AsyncSnapshot<DocumentSnapshot<Object>>”不能分配给参数类型“DocumentSnapshot<Object>”
【发布时间】:2021-08-19 12:07:52
【问题描述】:

我正在尝试构建一个应用程序。它获取用户凭证数据并显示在个人资料页面中。我得到的错误是

参数类型 'AsyncSnapshot'不能是 分配给参数类型“DocumentSnapshot”。

需要帮助!

child: StreamBuilder<DocumentSnapshot>(
          stream: FirebaseFirestore.instance
              .collection('users')
              .doc(Provider.of<Authentication>(context, listen: false)
                  .getUserUid)
              .snapshots(),
          builder: (context, snapshot) {
            if (snapshot.connectionState == ConnectionState.waiting) {
              return Center(
                child: CircularProgressIndicator(),
              );
            } else {
              return new Column(
                children: [
                  Provider.of<ProfileHelpers>(context, listen: false).headerProfile(context, snapshot)
                ],
              );
            }
          },
        ),

我认为错误在于 .headerProfile(context, snapshot)

下面是 headerProfile 的代码:

                GestureDetector(
              onTap: () {},
              child: CircleAvatar(
                backgroundColor: constantColors.transperant,
                radius: 60.0,
                backgroundImage: NetworkImage(snapshot['userimage']),
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 8.0),
              child: Text(snapshot['username'],
                  style: TextStyle(
                      color: constantColors.whiteColor,
                      fontWeight: FontWeight.bold,
                      fontSize: 16.0)),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 8.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Icon(EvaIcons.email, color: constantColors.greenColor),
                  Padding(
                    padding: const EdgeInsets.only(left:8.0),
                    child: Text(snapshot['useremail'],
                        style: TextStyle(
                            color: constantColors.whiteColor,
                            fontWeight: FontWeight.bold,
                            fontSize: 16.0)),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),

我认为错误来自 snapshot['username']snapshot['userimage']snapshot['useremail']强>

需要帮助!

【问题讨论】:

    标签: flutter google-cloud-firestore


    【解决方案1】:

    您需要从StreamBuilderbuilder 回调返回的AsyncSnapshot 中获取DocumentSnapshot

    通过在snapshot 上调用.data 来执行此操作。

    改变这个:

    .headerProfile(context, snapshot)
    

    到这里:

    .headerProfile(context, snapshot.data)
    

    【讨论】:

      猜你喜欢
      • 2022-01-01
      • 2021-11-07
      • 2021-07-07
      • 2021-06-08
      • 2023-02-18
      • 2021-09-30
      • 2022-08-18
      • 2021-08-06
      • 2021-04-14
      相关资源
      最近更新 更多