You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Flutter中使用Firebase Firestore获取当前用户数据?代码异常求助

Flutter Firestore 获取当前用户数据失败问题

我尝试使用从网上获取的代码,在Flutter中通过Firebase Firestore获取当前用户数据,但代码无法正常运行。

相关截图:

  • 代码报错截图:
    代码报错截图
  • Firestore数据结构截图:
    Firestore数据结构截图

使用的代码如下:

FirebaseFirestore.instance
    .collection("Users")
    .doc(uid)
    .get()
    .then((snapshot) {
  setState(() {
    // myName = (snapshot.data() as Map<String, dynamic>)['name'].toString(); // change this
    myUsername = (snapshot.data() as Map<String, dynamic>)['username'].toString(); // and this
    print(myUsername);
  });
});

内容的提问来源于stack exchange,提问作者Rohit Ranjan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 17:44:55