How to check time is after 3 min from a time or not in Flutter | Dart

Issue

I want to edit a form only after 3 minutes from the last edit. I am getting a last update time as string from api when loading that form for eg: 11:53:09. So i want to show submit form button only after 3 minutes from the last update time. Otherwise i want to show a Text that form can be edited after 3 minutes. How to acheive this functionality.

Solution

You can parse the last update time to DateTime and compare it with DateTime.now()

updatedTime = 11:53:09
DateFormat format = new DateFormat("hh:mm:ss");
updatedTime = format.format(updatedTime);

in your widget add this

DateTime.now() - updatedTime < 3 ? Text("form can be edited after 3 minutes") : Form()

Answered By – aki

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *