类型 'DateTime' 不是类型转换中类型 'int' 的子类型

type 'DateTime' is not a subtype of type 'int' in type cast

不太明白是什么问题,本地数据库的字段是DateTime类型的,我传的也是同一个类型

方法来自Json,错误在这里:

dateTimeCreateToken:
          serializer.fromJson<DateTime>(json['dateTimeCreateToken']),

来自 table 的列:

 DateTimeColumn get dateTimeCreateToken => dateTime()();

我将其提供给 FromJSON 方法的代码:

dateTimeCreateToken:
              dateNow.add(Duration(seconds: response.data["expires_in"])),

您收到的错误意味着值 json['dateTimeCreateToken'] 的类型为 'int;并且 Dart 正在尝试将 'int' 类型转换为 DateTime 类型,因此会引发错误。

您的 json['dateTimeCreateToken'] 类型是 int。我认为它是 millisecondsEpochmicrosecondsEpoch。请试试这个。


void main() async {
  var epoch = 1650012545317;
  var datetime = DateTime.fromMillisecondsSinceEpoch(epoch);
  
  print(datetime);
}