I have a Firestore Timestamp type field that I want to bring to my Flutter app, do some calculations, then print it on the screen. Everything is working fine for all other types besides the Timestamp. Here's my code (in a StaetefulWidget):
class _SummaryState extends State<Summary> {
//Firebase
var annual = DateTime.parse('2021-01-01');
int overhaul = 5000;
final firestoreInstance = FirebaseFirestore.instance;
void fetchAircraft() {
firestoreInstance
.collection("aircraft")
.doc(aircraftID)
.get()
.then((value) {
setState(() {
overhaul = value.data()["engine"]["overhaul"];
String conversion = value.data()["lastAnnual"].toString();
print('timestamp: $conversion');
annual = DateTime.parse(value.data()["lastAnnual"]);
}
}
void initState() {
super.initState();
fetchAircraft();
}
...code continues
Overhaul renders well but for the annual date, I get the error:
I/flutter (23628): timestamp: Timestamp(seconds=1596254400, nanoseconds=0) E/flutter (23628): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: type 'Timestamp' is not a subtype of type 'String'
Any idea how to convert Timestamp from Firestore to Flutter? All I want is to use the date from the timestamp to calculate the time between the last inspection and set the new one.