Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 如何在flatter中使用具有字段时间戳的类“flatter pub run build\u runner build”?_Firebase_Flutter_Dart_Timestamp - Fatal编程技术网

Firebase 如何在flatter中使用具有字段时间戳的类“flatter pub run build\u runner build”?

Firebase 如何在flatter中使用具有字段时间戳的类“flatter pub run build\u runner build”?,firebase,flutter,dart,timestamp,Firebase,Flutter,Dart,Timestamp,我正试图使用cmd flift pub run build_runner build从对象序列化JSON格式,但它始终显示以下消息: 运行JsonSerializableGenerator时出错 无法生成用于计时的fromJson代码。 提供的TypeHelper实例都不支持定义的类型 @JsonSerializable(explicitToJson: true) class RequestData { @JsonKey(required: true) String uid; Str

我正试图使用cmd flift pub run build_runner build从对象序列化JSON格式,但它始终显示以下消息:

运行JsonSerializableGenerator时出错 无法生成用于计时的fromJson代码。 提供的TypeHelper实例都不支持定义的类型

@JsonSerializable(explicitToJson: true)
class RequestData {
  @JsonKey(required: true)
  String uid;
  String phone;
  String email;
  String description;
  /// Tell json_serializable that "owner_name" should be
  /// mapped to this property.
  @JsonKey(name: 'owner-name')
  String ownerName;
  @JsonKey(name: 'location-detail')
  String locationDetail;
  int status;// 0 waiting, 1 accepted, 2 done, 3 DOING , 4 cancel
  List<String> imageUrls;
  @JsonKey( required: true, name: "time-taking", toJson: _timestampToJson/*,fromJson: _timeStampFromJson*/)
  Timestamp timeTaking;

  RequestData({this.uid, this.phone, this.email, this.description,
      this.ownerName, this.locationDetail, this.status, this.imageUrls,this.timeTaking});

  RequestData.none();
}

如何解决此问题?

我也有同样的问题,我的临时解决方案是创建一个JsonConverter以转换为DateTime:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:json_annotation/json_annotation.dart';

class TimestampConvertDatetime  implements JsonConverter<DateTime, Timestamp> {
  const TimestampConvertDatetime();
  @override
  DateTime fromJson(Timestamp json) {
    return json.toDate();
  }

  @override
  Timestamp toJson(DateTime object) {
    return Timestamp.fromDate(object);
  }
}

我也有同样的问题,我的临时解决方案是创建一个JsonConverter以转换为DateTime:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:json_annotation/json_annotation.dart';

class TimestampConvertDatetime  implements JsonConverter<DateTime, Timestamp> {
  const TimestampConvertDatetime();
  @override
  DateTime fromJson(Timestamp json) {
    return json.toDate();
  }

  @override
  Timestamp toJson(DateTime object) {
    return Timestamp.fromDate(object);
  }
}

凉的让我们试试这个解决方案。它很有效,谢谢你。酷!让我们试试这个解决方案。它很有效,谢谢