Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Timer Duration

Tags:

flutter

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.

like image 562
vuesajs Avatar asked Aug 22 '18 15:08

vuesajs


People also ask

How do you use time duration in Flutter?

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.

How do you do a countdown timer on Flutter?

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.

What is periodic 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.

Does Flutter timer run in background?

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.


1 Answers

You can use Future.delayed(...)

new Future.delayed(const Duration(seconds: time), () {
  // deleayed code here 
  print('delayed execution');
});
like image 135
Günter Zöchbauer Avatar answered Sep 30 '22 03:09

Günter Zöchbauer