Passing parameters from Flutter to Google Cloud Functions

213

replace

final results = await callable.call(['hello']);

with

final results = await callable.call({text: 'hello'});
Share:
213
James Han
Author by

James Han

Updated on December 31, 2022

Comments

  • James Han
    James Han over 1 year

    I'm trying to figure out how to communicate between Flutter and Google Cloud Functions. I wrote a simple Google Cloud Function that returns a list and a parameter but I keep receiving null when I call the function with a parameter. Why is this happening?

    The Flutter Function

    Future<void> getFruit() async {
       HttpsCallable callable = FirebaseFunctions.instance.httpsCallable('listFruit');
       final results = await callable.call(['hello']);
       List fruit = results.data;
       print(fruit);// ["Apple", "Banana", "Cherry", "Date", "Fig", "Grapes"]
     }
    

    The Google Cloud Function

    const functions = require("firebase-functions");
    
    exports.listFruit = functions.https.onCall((data, context) => {
      return ["Apple", "Banana", "Cherry", "Date", "Fig", "Grapes", data.text];
    });
    
    

    The Output

    flutter: [Apple, Banana, Cherry, Date, Fig, Grapes, null]
    
    

    Expected Output

    flutter: [Apple, Banana, Cherry, Date, Fig, Grapes, hello]
    

    Can someone please help me figure out why my expected output is not coming out?