How do I watch the Timer Duration to do something after a specific number of minutes/seconds before it ends? var duration = Duration(seconds: time); Which will end in an hour. I want for example when time passed 30 minutes call a function OR anything else.
To create a new Duration object, use this class's single constructor giving the appropriate arguments: const fastestMarathon = Duration(hours: 2, minutes: 3, seconds: 2); The Duration represents a single number of microseconds, which is the sum of all the individual arguments to the constructor.
Steps to add countdown timer in Flutter:Step 1: Make sure you have a StatefulWidget class. Step 2: Add the timer and duration variable. Step 3: Add a method called startTimer() to start the timer. Step 4: Add a method called stopTimer() to stop the timer.
A periodic timer is one that goes off periodically, notifying the thread (over and over again) that a certain time interval has elapsed. A one-shot timer is one that goes off just once.
A periodic Timer which runs only while the app's lifecycle is resumed. The default Dart timer also runs while the app is paused, e.g. if it is in the background.
You can use Future.delayed(...)
new Future.delayed(const Duration(seconds: time), () {
// deleayed code here
print('delayed execution');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With