Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter firebase function error : Response is not valid JSON object

Hello I tried to use firebase function by using Cloud_Functions Pkg but I got error in flutter consel , I tried to pass parameters in function which is UID of user .

Consel Error :

E/flutter (17871): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: [firebase_functions/internal] Response is not valid JSON object.
E/flutter (17871): #0      catchPlatformException
package:cloud_functions_platform_interface/…/utils/exception.dart:21
E/flutter (17871): #1      _rootRunBinary (dart:async/zone.dart:1378:47)
E/flutter (17871): #2      _CustomZone.runBinary (dart:async/zone.dart:1272:19)
E/flutter (17871): #3      _FutureListener.handleError (dart:async/future_impl.dart:166:20)
E/flutter (17871): #4      Future._propagateToListeners.handleError (dart:async/future_impl.dart:716:47)
E/flutter (17871): #5      Future._propagateToListeners (dart:async/future_impl.dart:737:24)
E/flutter (17871): #6      Future._completeError (dart:async/future_impl.dart:547:5)
E/flutter (17871): #7      _completeOnAsyncError (dart:async-patch/async_patch.dart:264:13)
E/flutter (17871): #8      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart)
package:flutter/…/services/platform_channel.dart:1
E/flutter (17871): <asynchronous suspension>

Firebse Function :

exports.helloWorld = functions.https.onCall((data, context) => {
  return data.data()['uid'];
});

Flutter run function from Firebase :

    IconButton(
        icon: Icon(Icons.add),
        onPressed: () async {
          HttpsCallable callable =
              FirebaseFunctions.instance.httpsCallable('listFruit');
          final results = await callable.call(<String, dynamic>{
            'uid': '123',
          });
          print(results
              .data.toString()); // ["Apple", "Banana", "Cherry", "Date", "Fig", "Grapes"]
        });

My goal :

pass parameters to firebase function .

like image 343
Khalifa Alkhatri Avatar asked Oct 20 '25 13:10

Khalifa Alkhatri


1 Answers

I had the same error and it was due to the fact that the region was not provided, which seems to be required if the function is not deployed in us-central1. Following their documentation, you can perform the call like this:

FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('listFruit');
like image 154
Naoj Avatar answered Oct 23 '25 04:10

Naoj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!