skip to Main Content

I have a huge function in my Flutter app, and every time I call it, it takes a long time to run. I want to rewrite it as a google cloud function and call it in my app in order to minimize the loading time.
Here is the way I call my backend function.

the title is a string value,
the arrayRanges is an array of arrays

     try {
      final result = FirebaseFunctions.instance
          .httpsCallable('generatingAppointments')
          .call(
        {
          'title': daysOfHelp[k].title,
          'arrayRanges': ArrayOfAllTheDayRanges,
        },
      );
      print("generatingAppointments No error");
    } on FirebaseFunctionsException catch (error) {
      print("generatingAppointments error");
      print(error.code);
      print(error.details);
      print(error.message);
    }

and after this my UI navigate to another page in my app immediately

and this is a simple code in the backend to test if I call the backend function correctly

   exports.generatingAppointments = functions.https.onCall((data, context) => {
    functions.logger.info("generatingAppointments Is running");
    console.log('New Message written');
  });

but the problem is I don’t see any of the print I wrote in the backend in my logs.

Note: I don’t need the result to return to my app, I will store it in the database and use it later.

EDIT:
when I removed ArrayOfAllTheDayRanges parameter the logs shows in my consol, but I don’t know why this parameter cause a problem
ArrayOfAllTheDayRanges is an array of arrays

2

Answers


  1. Chosen as BEST ANSWER

    I found out that my problem was in sending ArrayOfAllTheDayRanges which is an array of arrays (2-dimensional array). so when I remove it every thing went will


  2. To be able to see the logs when you use console.log, you need to require the below dependencies

    For console.log

    require("firebase-functions/logger/compat");
    

    e.g console.log(username)

    For logger.log

    const { warn } = require("firebase-functions/logger");
    

    e.g.

    logger.log() commands have the INFO log level.
    
    logger.info() commands have the INFO log level.
    
    logger.warn() commands have the WARNING log level.
    
    logger.error() commands have the ERROR log level.
    

    For functions.logger.log

    const functions = require("firebase-functions");
    

    e.g.

    functions.logger.log("Hello");
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search