如何从Flutter调用本地Firebase函数(在仿真器中)? [英] How can I call local Firebase Functions (in Emulator) from Flutter?

查看:94
本文介绍了如何从Flutter调用本地Firebase函数(在仿真器中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地仿真器中设置了Cloud Functions.我编写了一些函数,并使用功能模拟器在浏览器中对其进行了测试.现在,我尝试从本地Flutter应用程序中调用这些功能,而无需部署它们.但是,我找不到将Flutter App连接到函数的localhost API的方法. 反正有这样做吗?

I set up Cloud Functions in the local emulator. I wrote a few functions and tested them in the browser with the function emulator. Now I am trying to call these functions from my local Flutter app without deploying them. However, i cannot find a way to connect my Flutter App to the localhost API of the functions. Is there anyway to do that?

推荐答案

步骤:

  1. 导入软件包:

  1. Import the package:

import 'package:cloud_functions/cloud_functions.dart';

  • 创建实例:

  • Create an instance:

    static final _functions = CloudFunctions.instance;
    

  • 将其连接到仿真器:

  • Wire it up to the emulator:

    final origin = Platform.isAndroid ? 'http://10.0.2.2:5001' : 'http://localhost:5001';
    _functions.useFunctionsEmulator(origin: origin);
    

  • 另请参阅:

    • Error connecting to local Firebase functions emulator from Flutter app
    • The code for the useFunctionsEmulator function in the Github repo.

    这篇关于如何从Flutter调用本地Firebase函数(在仿真器中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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