您好,我目前正在使用 firebase 的本地模拟器和 flutter。但是,我使用的是真实设备而不是模拟器,因此我不知道如何连接到我的笔记本电脑本地主机。我目前正在使用此代码
// [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
}
},
...
}
flutter 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,
);
关于firebase - Flutter firebase 从真实设备连接到模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67973536/