【问题标题】:Can't get access to firestore local emulator suite in flutter无法在颤振中访问 Firestore 本地仿真器套件
【发布时间】:2021-08-09 16:52:13
【问题描述】:

我无法在 Flutter 中连接到 Firestore 模拟器。它反映在 Firebase 主控制台中。 我用的是安卓模拟器

void initState() {
super.initState();
firestore = FirebaseFirestore.instance;
firestore.settings = Settings(
  host: '10.0.2.2:8080',
  sslEnabled: false,
);

firestore.collection('tokens').add({'data': 16});
}

我根据文档配置了模拟器。

─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app │
│ i  View Emulator UI at http://localhost:4000                │
└─────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator  │ Host:Port      │ View in Emulator UI             │
├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ localhost:5001 │ http://localhost:4000/functions │
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ localhost:8080 │ http://localhost:4000/firestore │
└───────────┴────────────────┴─────────────────────────────────┘
  Emulator Hub running at localhost:4400
  Other reserved ports: 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.

!  It looks like you're trying to access functions.config().functions but there is no value there. You can learn more about setting up config here: https://firebase.google.com/docs/functions/local-emulator

firebase 版本:

firebase --version 
9.11.0

firebase.json

 {
  "emulators": {
    "functions": {
      "port": 5001
    },
    "ui": {
      "enabled": true
    },
    "firestore": {
      "port": 8080
    }
  }
}

http://localhost:4000/firestore 上没有显示数据,即使更改了设置(主机),数据也反映在主 firebase 控制台上。

我有时会收到此错误:

MissingPluginException (MissingPluginException(未找到实现 用于通道上的方法 DocumentReference#set plugins.flutter.io/firebase_firestore))

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
cupertino_icons: ^1.0.1
  firebase_auth: ^0.20.1
  equatable: ^1.2.6
  bloc: ^6.1.3
  flutter_bloc: ^6.1.3
  firebase_core: ^0.7.0
  cloud_firestore: ^0.16.0
  google_sign_in: "^4.5.1"
  flutter_rating_bar: ^4.0.0
  image_picker: ^0.6.7+17
  firebase_storage: ^7.0.0
  syncfusion_flutter_calendar: ^18.4.42
  simple_time_range_picker: ^0.0.2
  firebase_messaging: ^8.0.0-dev.15
  cloud_functions: ^0.9.0

非常感谢一些帮助。谢谢

【问题讨论】:

  • 我觉得有必要问几个愚蠢的问题:您是否尝试过使用 IP 而不是“localhost”标签进行连接?您是否正在使用已启用的功能?如果是这样,你有enabled clear text communication吗?最后,您是否添加了您希望看到的数据? Firestore 模拟器毕竟是一个模拟器,因此它不会包含您的生产数据,因为它是为开发环境而不是生产环境设计的。
  • 是的,我尝试过使用 IP。我已经尝试向其中添加数据。当然,先生,它不会有生产数据。使用 Android 10,因此启用明文通信没有问题。
  • 抱歉,我才意识到,您使用的是带有 Flutter 的基础 Firebase 而不是 Flutterfire?我几乎完全忘记了FirebaseExtended,所以我并没有真正考虑过。但是,是的,Flutter 有一个更好地集成了 Firebase 的发行版,你仍然需要模拟器。不过,如果可以相信this article,那么您已经正确设置了初始化......对不起,我之前没有注意到data.add()。我建议尝试 Flutterfire 而不是 Flutter,应该有助于实现...
  • 实施,这就是我要结束该评论的内容。但是字符限制是一回事
  • 没问题。但我正在使用 FlutterFire。

标签: android flutter google-cloud-firestore firebase-tools


【解决方案1】:

您需要使用最新版本的依赖项。您可以查看最新版本here

更新依赖项后,您必须运行:

flutter clean
flutter packages get

【讨论】:

    【解决方案2】:

    对我来说,问题是生产数据仍在我的应用程序的缓存中。重新安装后就可以了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-18
      • 1970-01-01
      • 2021-09-03
      • 2021-12-04
      • 1970-01-01
      • 2021-05-14
      • 1970-01-01
      • 2019-06-20
      相关资源
      最近更新 更多