Trying to convert Firestore Timestamp to DateTime in Flutter I'm getting always an error, tried all of the solutions, none worked ( last tried How to print Firestore timestamp as formatted date and time)
Here's my code below;
Code
factory UserModel.fromMap(Map<String, dynamic> map) {
return UserModel(
name: map['name'],
email: map['email'],
username: map['username'],
registerDate:
DateTime.fromMillisecondsSinceEpoch(map['registerDate'] * 1000),
id: map['id'],
imageUrl: map['imageUrl'],
cvUrl: map['cvUrl'],
phoneNumber: map['phoneNumber'],
education: Education.fromMap(map['education']),
location: Location.fromMap(map['location']),
lookingForIntern: map['lookingForIntern'],
);
}
Error
'Timestamp' has no instance method '*'.
Receiver: Instance of 'Timestamp'
Converted DateTime to Timestamp, and changed
registerDate:
DateTime.fromMillisecondsSinceEpoch(map['registerDate'] * 1000),
to
registerDate:map['registerDate']
now getting error below;
Converting object to an encodable object failed: Instance of 'Timestamp'
but print(map['registerDate'])
prints Timestamp(seconds=1632412800, nanoseconds=0)