Flutter Web调用CloudFunction参数报错

Calling CloudFunction parameters from Flutter Web gives an error

我从 Flutter Web 中这样调用函数:

//* Call createUserDocuments
final _params = <String, dynamic>{
      param1: 'param1',
      param2: 1234,

};

final response = await CloudFunctions.instance
  .getHttpsCallable(functionName:'function1')
   .call(_params).timeout(Duration(seconds: 30));

但我总是在 Firebase 控制台中收到此错误:

error: syntax error at or near "{"

控制台中的另一条消息显示 INTERNAL

云函数

exports.function1 = functions
.runWith({ memory: "256MB", timeoutSeconds: 10 })
.https.onCall(async (data, context) => {

const param1 = data['param1']; 
const param2 = data['param2'];
const date = admin.firestore.Timestamp.now();

console.log(`Got called: ${param1} ${param2} ${date.toMillis}`);

});

而且,如果我调用一个不需要任何参数的函数,它就可以工作。

我的 Flutter 医生:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 1.23.0-18.1.pre, on Mac OS X 10.15.7 19H2 x86_64, locale en-US)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.50.1)
[✓] Connected device (3 available)

• No issues found!

这里还有我需要补充的信息吗?

final _params = <String, dynamic>{
      param1: 'param1',
      param2: 1234,
};

这里的键应该是字符串。所以它应该像-

final _params = <String, dynamic>{
      'param1': 'param1',
      'param2': 1234,
};

我发现了我的问题。因此,在 Cloud Function 代码中,我向其中一个参数添加了一个 .toMillis,因为它是一个 Timestamp 对象。

但正确的语法应该是 .toMillis()。否则我只是传递函数而不是调用函数。

伙计们,请永远记得加上括号。 ;-)

*更多注意事项:之前我说过从Flutter App调用时云功能正在运行。抱歉我的错误,因为我完全忘记了在其中添加 .toMillis 函数调用。我已解决问题以反映这一点