firebase - Flutter firebase 从真实设备连接到模拟器

标签 firebase flutter google-cloud-functions firebase-tools

您好,我目前正在使用 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/

相关文章:

android - Firebase 插件错误 400 错误 : invalid_scope into android studio

flutter - 调用 Firebase.initializeApp() 返回 '(PlatformException(null-error, Host platform returned null value for non-null return value., null, null))'

node.js - Firebase 云函数 - 同时使用多个 HTTP 触发器会发生什么情况

javascript - Firestore Set Catch 最后

firebase - 使用 Firebase getSignedUrl() 进行签名错误

swift - 从自动 ID 数据库子项中检索数据

java - 如何使新添加的项目位于 firebase 中现有的 id 下?

php - Firebase:如何使用相同的自定义 token 从不同环境(JS 和 iOS)进行身份验证?

dart - 如何在我的 Flutter 应用程序中重置基本路由 - 即弹出任何路由并使用 Navigator 将其替换为新路由

flutter - 未设置背景图片,其显示在顶部