【问题标题】:retrieving current user to show in personal profile检索当前用户以显示在个人资料中
【发布时间】:2021-11-04 00:19:15
【问题描述】:

您好,我正在尝试从 firebase 检索当前用户信息,但它向我显示了此错误的错误

这是我的代码

  final auth = FirebaseAuth.instance;
  final db = FirebaseFirestore.instance;
  User? user = FirebaseAuth.instance.currentUser;

Padding(
            padding: EdgeInsets.only(left: 20, right: 20),
            child: StreamBuilder(
              stream: db
                  .collection("Users")
                  .doc("list_students")
                  .collection("Students")
                  .doc(user!.uid)
                  .snapshots(),
              builder: (BuildContext context, AsyncSnapshot snapshot) {
                if (!snapshot.hasData) {
                  return Center();
                }
                return ListView.builder(
                    itemCount: snapshot.data.length,
                    itemBuilder: (BuildContext context, int index) {
                      return Stack;

这是我的火力基地的截图

【问题讨论】:

    标签: firebase flutter dart


    【解决方案1】:

    首先,尝试打印 'snapshot' 和 'snapshot.data',因为您已经从 firebase 获得了正确的数据。

    【讨论】:

      【解决方案2】:

      您需要将snapshot.data 转换为List 类型,然后才能在snapshot.data 上调用length 方法。我无法从您包含的代码中看出snapshot.data 的基础类型是什么。

      另一种方法是在builder 标头中指定AsyncSnapshot<List<String>> snapshot,假设基础数据类型是List<String>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-09
        • 1970-01-01
        • 2021-10-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-26
        • 2019-06-30
        相关资源
        最近更新 更多