calling firebase cloud function in flutter

2,098

As far as I can see in this documentation you can just pass the parameters into the call(...). Did you give that a try?

Share:
2,098
James 666
Author by

James 666

Flutter developer, 2 years and counting...

Updated on December 26, 2022

Comments

  • James 666
    James 666 over 1 year

    I've sent a function to firebase through typescript and don't know how to access it in my flutter app. The code needs to send the uid of the firebase user (the user will always already be logged in, so this isn't an issue) but then I also need to write into the function through message parameter, as is shown in my typescript code below. Again, I am unsure how to do this in Flutter.

    This is my typescript code:

    import * as functions from 'firebase-functions';
    
    export const testFunction = functions.https.onCall( async (data, context) => {
        const uid = context.auth && context.auth.uid;
        const message = data.message;
    
        return `${uid} sent a message of ${message}`
    });
    

    Here is my Flutter code:

    import 'package:cloud_functions/cloud_functions.dart';
    
    Future<void> getFunction() async {
      HttpsCallable callable = FirebaseFunctions.instance.httpsCallable('testFunction', options: HttpsCallableOptions(timeout: Duration(seconds: 5)));
      final results = await callable();
      print('${results.data}');
    }
    
    @override
      void initState() {
        super.initState();
        getFunction();
    }
    
    
  • James 666
    James 666 over 3 years
    So I changed it to this: ``` final results = await callable.call(<dynamic, String>{ 'message': 'hello', }); print('${results.data}'); ```
  • James 666
    James 666 over 3 years
    but nothing was printed in the console
  • Frank van Puffelen
    Frank van Puffelen over 3 years
    Good to hear James 👍