Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an Interval in Flutter? [duplicate]

Recently I tried to make an interval in flutter but I didn't see anything like setInterval(function(){}, 1000) in JavaScript. Does it exist in Flutter?

like image 549
Michael Avatar asked Mar 23 '18 18:03

Michael


People also ask

What is interval in flutter?

Interval class Null safetyAn Interval can be used to delay an animation. For example, a six second animation that uses an Interval with its begin set to 0.5 and its end set to 1.0 will essentially become a three-second animation that starts three seconds later.


1 Answers

you can use Timer for that.

Timer timer = new Timer(new Duration(seconds: 5), () {    debugPrint("Print after 5 seconds"); }); 

EDITED

as pointed by @MoeinPorkamel in comments. Above answer is more like setTimeout instead of setInterval! Those who need interval, you can use:

// runs every 1 second Timer.periodic(new Duration(seconds: 1), (timer) {    debugPrint(timer.tick.toString()); }); 

To use Timer you need to import 'dart:async';

like image 57
Ajay Kumar Avatar answered Sep 20 '22 19:09

Ajay Kumar