【发布时间】:2021-01-12 14:07:03
【问题描述】:
我正在为我的 Flutter 应用程序使用实时数据库和函数。我已经为数据库和函数设置了本地模拟器,因此我可以在本地测试函数而无需部署成本。现在我想将我的 Flutter 应用程序连接到这些本地模拟器,但我在寻找如何做时遇到了一些麻烦。
FlutterFire 文档描述了如何为 Firestore (https://firebase.flutter.dev/docs/firestore/usage#emulator-usage) 执行此操作,但不适用于实时数据库。肯定有办法连接到模拟器,即使我使用的是实时数据库?
我尝试了以下方法:
String host = Platform.isAndroid ? '10.0.2.2:4000' : 'localhost:4000';
FirebaseDatabase database = FirebaseDatabase(
app: Firebase.app(),
databaseURL: host,
);
但这给了我错误:
未处理的异常:PlatformException(错误,指定的 Firebase 数据库 URL 无效:10.0.2.2:4000,null)
我在 pub 上使用 firebase_core 和 firebase_database 包。
【问题讨论】:
标签: firebase flutter firebase-realtime-database