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?
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);
});
To user Timer
you need to import 'dart:async';
Tags: androidandroid