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

Flutter Web无法读取含用户ID的Firebase集合,移动端却正常工作的问题求助

Flutter Web无法读取含用户ID的Firebase集合,移动端却正常工作的问题求助

大家好,我碰到了一个很棘手的问题:我的Flutter移动端和Web端共用同一个Firebase Firestore数据库,但Web端始终读不到集合里的全部数据。

具体情况如下:我用这段代码获取集合数据:

final collection = FirebaseFirestore.instance.collection(_allReports);

print('* * * allReports - ${(await collection.get()).docs.length}');

控制台输出结果是0,但Firebase后台的截图明明显示这个集合里有2条数据。

我试了两种特殊情况,结果都能正常读取数据:

  • 如果用随机符号代替用户ID创建文档,Web端可以正常读取到内容
  • 如果直接使用完整路径'all_reports/user_id/reports/'来获取数据,也能顺利拿到结果

我的Firestore安全规则是这样的:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if isUserAuthenticated();
    }
    match /all_reports/{document=**} {
      allow read: if true;
    }
    /* Functions */
    function isUserAuthenticated() {
      return request.auth.uid != null;
    }
  }
}

有没有大佬能帮我找出问题所在,解决这个困惑呀?

备注:内容来源于stack exchange,提问作者Nurbek Batyrzhan uulu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.22 09:38:08