I want to create a function which does not allow the user to remove the appointment once the timestamp for the appointment has past already. But what i tried below does not work, i hope to get some guidance from you guys
My widget.filter is a var which has the timestamp value from firebase
DateTime currentPhoneDate = DateTime.now(); //DateTime
Timestamp myTimeStamp = Timestamp.fromDate(currentPhoneDate); //To TimeStamp
DateTime myDateTime = myTimeStamp.toDate(); // TimeStamp to DateTime
print("current phone data is: $currentPhoneDate");
print("current phone data is: $myDateTime");
if(myTimeStamp < widget.filter){
print('work');
}else{
print('fail');
}
CodePudding user response:
Flutter has a built in function for this purpose, and if I understand your question correctly what you'll want to do is change:
if(myTimeStamp < widget.filter) {}
to:
if(myTimeStamp.isAfter(widget.filter)) {}
CodePudding user response:
DateTime currentPhoneDate = DateTime.now();
Timestamp myTimeStamp = Timestamp.fromDate(currentPhoneDate);
DateTime myDateTime = myTimeStamp.toDate();
print("myTimeStamp is: $myTimeStamp");
print("currentPhoneDate is: $currentPhoneDate");
print("myDateTime is: $myDateTime");
// if widget.filter DataType is not Timestamp then first convert it to Timestamp.
if (myTimeStamp.millisecondsSinceEpoch <
widget.filter.millisecondsSinceEpoch) {
print('work');
} else {
print('fail');
}