3

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();
}

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

3 Comments

So I changed it to this: ``` final results = await callable.call(<dynamic, String>{ 'message': 'hello', }); print('${results.data}'); ```
but nothing was printed in the console
Good to hear James 👍

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.