'Unhandled Exception: FormatException: Trying to read yyyy from null at position 0
I tried to use dateTime to open or close the access to the registration form, I saved the value of open or close date in my Firebase.. so I must retrieve the date value from the database, and compare with the user current time. To get the country current time, I used WorldTime API.. Please can you check my code to let me know I dit a mistake or error ?
Thanks a lot
await FirebaseFirestore.instance
.collection("DateTimeActivity")
.doc("OpenTime")
.snapshots()
.listen((event) {
var openDateTime = event.get("OpenTime");
var closeDateTime = event.get("closeTime");
DateFormat myFormat = DateFormat('yyyy-MM-dd');
DateTime open = myFormat.parse(openDateTime);
DateTime close = myFormat.parse(closeDateTime);
//DateTime current = myFormat.parse(currentTime);
if (DateTime.parse(currentTime).isBefore(open)) {
isTime = false;
} else if (DateTime.parse(currentTime).isAfter(close)) {
isTime = false;
} else {
isTime = true;
}
});
return isTime;
} ```
Solution 1:[1]
even thought you set a date in firebase it will store it as a timestamp.
try:
myFormat.parse((openDateTime as TimeStamp).toDate())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Simon Danninger |
