如何在Flutter应用中连接到本地实时数据库仿真器? [英] How do I connect to my local Realtime Database emulator in my Flutter app?

查看:81
本文介绍了如何在Flutter应用中连接到本地实时数据库仿真器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Flutter应用程序使用实时数据库和函数.我已经为数据库和函数设置了本地仿真器,因此我可以在本地测试函数,而无需支付部署成本.现在,我想将Flutter应用程序连接到这些本地仿真器,但是在查找操作方法时遇到了一些麻烦.

I am using the Realtime Database and Functions for my Flutter app. I've set up local emulators for both Database and Functions, so I can test Functions locally without the deployment cost. Now I want to connect my Flutter app to these local emulators, but I am having some trouble finding out how to do it.

FlutterFire文档介绍了如何为Firestore( https://firebase.flutter.dev/docs/firestore/usage#emulator-usage ),但不适用于实时数据库.即使我使用的是实时数据库,肯定也必须有一种方法可以连接到仿真器?

The FlutterFire docs describes how to do this for Firestore (https://firebase.flutter.dev/docs/firestore/usage#emulator-usage), but not for the Realtime Database. Surely there must be a way to connect to the emulators, even though I am using the Realtime Database?

我尝试了以下操作:

String host = Platform.isAndroid ? '10.0.2.2:4000' : 'localhost:4000';
    FirebaseDatabase database = FirebaseDatabase(
      app: Firebase.app(),
      databaseURL: host,
    );

但这给了我错误:

未处理的异常:PlatformException(错误,指定的Firebase数据库网址无效:10.0.2.2:4000,空)

Unhandled Exception: PlatformException(error, Invalid Firebase Database url specified: 10.0.2.2:4000, null)

我正在pub上使用firebase_core和firebase_database软件包.

I am using the firebase_core and firebase_database packages on pub.

推荐答案

根据Android的Firebase文档,使用实时数据库模拟器需要调用 database.useEmulator("10.0.2.2",9000).快速搜索FlutterFire代码并没有发现此类调用,因此似乎FlutterFire尚未实现模拟器的使用.

According to the Firebase documentation for Android, using the Realtime Database emulator requires a call database.useEmulator("10.0.2.2", 9000). A quick search of the FlutterFire code shows no such calls, so it seems that emulator usage isn't implemented in FlutterFire yet.

我也找不到

I also couldn't find an open issue for it, so you might want to file a feature request.

这篇关于如何在Flutter应用中连接到本地实时数据库仿真器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆