Flutter firebase 从真实设备连接到模拟器 [英] Flutter firebase connect to emulator from real device

查看:19
本文介绍了Flutter firebase 从真实设备连接到模拟器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hi I am currently using firebase's local emulator and flutter. However, I am using a real device and not a simulator therefore I do not know how to connect to my laptops localhost. I am currently using this code

  // [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,
  );

推荐答案

好的,我通过以下两个步骤解决了问题:

Ok I fixed the problem by these two steps:

firebase.json:

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:

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,
);

这篇关于Flutter firebase 从真实设备连接到模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆