首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >颤动firebase从真实设备连接到仿真器

颤动firebase从真实设备连接到仿真器
EN

Stack Overflow用户
提问于 2021-06-14 23:56:14
回答 1查看 221关注 0票数 1

您好,我目前使用的是firebase的本地模拟器和flutter。但是,我使用的是真实的设备,而不是模拟器,因此我不知道如何连接到我的笔记本电脑本地主机。我目前正在使用这段代码

代码语言:javascript
复制
  // [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,
  );
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-15 01:56:53

好的,我通过以下两个步骤修复了这个问题:

firebase.json:

代码语言:javascript
复制
{
  ...
  "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:

代码语言:javascript
复制
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,
);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67973536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档