简体   繁体   English

带参数的 Flutter 云函数调用

[英]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:和一个 JS 文件:

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.我总是得到“3100000012120000”,所以基本上我无法从 mobil 取回我的日期时间参数。 It is working in browser.它在浏览器中工作。 How to do this in a mobil app?如何在移动应用程序中执行此操作?

req.parameters is the correct word or WHAT? req.parameters 是正确的词还是什么?

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";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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