简体   繁体   中英

Flutter cloud function call with parameters

I have a flutter app, my code looks like this:

  dynamic result = await CloudFunctions.instance.getHttpsCallable(functionName: 'getAllItemsAfterDatetime').call(
    <String, dynamic> {"datetime": "1563109861142"}
  );

and a JS file:

exports.getAllItemsAfterDatetime= functions.https.onRequest(async (req, res) => {
  if (!mysqlPool) {
    mysqlPool = mysql.createPool(mysqlConfig);
  }

  let datetime = req.body.datetime;
  if (datetime == null) datetime = req.query.datetime;
  if (datetime == null) datetime = req.params.datetime;
  if (datetime == null) datetime = "3100000012120000";

  mysqlPool.query('SELECT * FROM items as res WHERE datetime > ' + datetime, (err, results) => {
    if (err) {
      console.error(err);
      res.status(500).send(err);
    } else {
      res.status(200).send({cnt: res.length, data: JSON.stringify(results)});
    }
  });

I got allways "3100000012120000", so basically I can't get my datetime param back from mobil. It is working in browser. How to do this in a mobil app?

req.parameters is the correct word or WHAT?

Thanks

UPDATE: The solution

  //from browser
  let datetime = req.body.datetime; 

  //from mobile
  if (datetime == null) datetime = req.body.data.datetime; 

  //if not set
  if (datetime == null) datetime = "3100000012120000";

solution was

 //from browser
  let datetime = req.body.datetime; 

  //from mobile
  if (datetime == null) datetime = req.body.data.datetime; 

  //if not set
  if (datetime == null) datetime = "3100000012120000";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM