Home > Enterprise >  type 'DateTime' is not a subtype of type 'int' in type cast
type 'DateTime' is not a subtype of type 'int' in type cast

Time:04-15

I don't quite understand what the problem is, the field in the local database is of the DateTime type and I pass the same type

method fromJson, the error is here:

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

column from table:

 DateTimeColumn get dateTimeCreateToken => dateTime()();

the code where I give it to the FromJSON method:

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

CodePudding user response:

Your json['dateTimeCreateToken'] type is int. I thing it is millisecondsEpoch or microsecondsEpoch. Please try this.


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

enter image description here

CodePudding user response:

The error you are getting means that the value json['dateTimeCreateToken'] is of type 'int; and Dart is trying to convert an 'int' Type into a DateTime Type and so it is throwing an error.

  • Related