【问题标题】:How can I call local Firebase Functions (in Emulator) from Flutter?如何从 Flutter 调用本地 Firebase 函数(在模拟器中)?
【发布时间】:2020-11-09 16:07:51
【问题描述】:

我在本地模拟器中设置了 Cloud Functions。我写了一些函数,并在浏览器中使用函数模拟器对其进行了测试。现在我试图从我的本地 Flutter 应用程序调用这些函数而不部署它们。但是,我找不到将 Flutter App 连接到函数的 localhost API 的方法。 有什么办法吗?

【问题讨论】:

    标签: firebase flutter google-cloud-firestore google-cloud-functions


    【解决方案1】:

    分步:

    1. 导入包:

      import 'package:cloud_functions/cloud_functions.dart';
      
    2. 创建一个实例:

      static final _functions = CloudFunctions.instance;
      
    3. 将其连接到模拟器:

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

    另见:

    【讨论】:

      猜你喜欢
      • 2020-10-26
      • 2021-09-12
      • 2020-11-09
      • 1970-01-01
      • 2021-11-10
      • 2021-03-06
      • 2020-02-29
      • 2020-10-22
      相关资源
      最近更新 更多