Flutter cloud_functions参数无效:“ GeoPoint”的实例

时间:2020-01-01 22:52:32

标签: firebase flutter dart google-cloud-functions

嗨,我在尝试在flutter中运行可调用的firebase函数时遇到了此错误。我不知道原因的根本,将不胜感激。

final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
    functionName: 'firebaseFunction',
);

dynamic resp = await callable.call(<String, dynamic>{
    "geoPoint" : geoPoint, //This is a variable with firestore class type GeoPoint
});

返回错误

未处理的异常:无效的参数:'GeoPoint'的实例

2 个答案:

答案 0 :(得分:0)

感谢Peter Haddad指出了错误的根本原因。

只能使用null,String,num,List或Map类型

我使用的这种方法是这样。扑朔迷离

dynamic resp = await callable.call(<String, dynamic>{
  ///I split geopoint into its latitude and longitude
  "lat" : geoPoint.latitude,
  "long" : geoPoint.longitude,

  ///I split timestamp into its seconds and nanoseconds
  "seconds" : timestamp.seconds,
  "nanoseconds" : timestamp.nanoseconds,
});

我将geopoint分为纬度和经度。通过将时间戳分为几秒和十亿分之一秒,这也适用于时间戳。然后在firebase函数中,我收集了数据并使用admin.firestore.XXX()

重建了类。
const lat = data["lat"];
const long = data["long"];
const geoPoint = new admin.firestore.GeoPoint(lat, long);

const seconds = data["seconds"];
const nanoseconds = data["nanoseconds"];
const timeStamp = new admin.firestore.Timestamp(seconds, nanoseconds);

答案 1 :(得分:-1)

如错误所述,由于不支持,您不能将modal的实例作为值传递给方法geoPoint。根据文档,支持以下内容:

call

https://github.com/FirebaseExtended/flutterfire/blob/master/packages/cloud_functions/lib/src/https_callable.dart

示例:

/// Executes this Callable HTTPS trigger asynchronously.
  ///
  /// The data passed into the trigger can be any of the following types:
  ///
  /// `null`
  /// `String`
  /// `num`
  /// [List], where the contained objects are also one of these types.
  /// [Map], where the values are also one of these types.
  ///
  /// The request to the Cloud Functions backend made by this method
  /// automatically includes a Firebase Instance ID token to identify the app
  /// instance. If a user is logged in with Firebase Auth, an auth ID token for
  /// the user is also automatically included