firebase - Flutter firebase 从真实设备连接到模拟器
问题描述
嗨,我目前正在使用 firebase 的本地模拟器和颤振。但是,我使用的是真实设备而不是模拟器,因此我不知道如何连接到我的笔记本电脑 localhost。我目前正在使用此代码
// [Firestore | localhost:8080]
FirebaseFirestore.instance.settings = const Settings(
host: "localhost:8080",
sslEnabled: false,
persistenceEnabled: false,
);
// [Authentication | localhost:9099]
await FirebaseAuth.instance.useEmulator("http://localhost:9099");
FirebaseFunctions.instance.useFunctionsEmulator(
origin: "http://localhost:5001"
);
// [Storage | localhost:9199]
await FirebaseStorage.instance.useEmulator(
host: "localhost",
port: 9199,
);
解决方案
好的,我通过以下两个步骤解决了问题:
firebase.json:
{
...
"emulators": {
"auth": {
"host": "0.0.0.0", <--- Adding host
"port": 9099
},
"functions": {
"host": "0.0.0.0",
"port": 5001
},
"firestore": {
"host": "0.0.0.0",
"port": 8080
},
"storage": {
"host": "0.0.0.0",
"port": 9199
},
"ui": {
"enabled": true
}
},
...
}
颤振 main.dart:
const String localIp = "You local ip goes here";
FirebaseFirestore.instance.settings = const Settings(
host: localIp+":8080",
sslEnabled: false,
persistenceEnabled: false,
);
await FirebaseAuth.instance.useEmulator("http://"+localIp+":9099");
FirebaseFunctions.instance.useFunctionsEmulator(
origin: "http://"+localIp+":5001"
);
await FirebaseStorage.instance.useEmulator(
host: localIp,
port: 9199,
);
推荐阅读
- python - 来自 scapy 的层未找到错误
- azure-devops - 如何根据参数值有条件地设置 Azure DevOps yaml 变量
- php - PHP-Mysql:从第一行和第二行输出的 sql 中的 PHP 回显值
- wordpress - Cloudfront 的 Terraform:InvalidHeadersForS3Origin,但我没有将 [*] 传递给任何 S3 源
- angular - 生产中的角度重定向网址
- aws-documentdb - AWS DocumentDb 开发最佳实践
- javascript - 合并一个属性相同的对象数组,同时将另一个属性的唯一值转移到数组中
- .net - 具有单文件可执行文件的 .NET 5.0 Linux 中的原始程序集位置
- javascript - 请任何人告诉我我做了什么我的网站显示日期和时间在刷新页面时没有被重置
- node.js - Mongodb 响应延迟