How can I call local Firebase Functions (in Emulator) from Flutter?

不想你离开。 提交于 2021-01-20 12:06:39

问题


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:


In steps:

  1. Import the package:

    import 'package:cloud_functions/cloud_functions.dart';
    
  2. Create an instance:

    static final _functions = CloudFunctions.instance;
    
  3. Wire it up to the emulator:

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

Also see:

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


来源:https://stackoverflow.com/questions/62994836/how-can-i-call-local-firebase-functions-in-emulator-from-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!