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?
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.
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';
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