Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 456
James 666 Avatar asked Dec 01 '25 09:12

James 666


1 Answers

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

like image 50
Frank van Puffelen Avatar answered Dec 04 '25 00:12

Frank van Puffelen