arbis
arbis

Reputation: 1950

calling firebase cloud function in flutter

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

Upvotes: 3

Views: 5455

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598668

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

Upvotes: 3

Related Questions