flutterdrift

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


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"])),

Solution

  • 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