Future.delayed(Duration(milliseconds: 100), () {
// Do something
});
Timer(Duration(seconds: 5), () {
print(" This line is execute after 5 seconds");
});
Timer(Duration(seconds: 3), () {
print("Yeah, this line is printed after 3 second");
});
// repeatedly :
Timer.periodic(Duration(seconds: 5), (timer) {
print(DateTime.now());
});
In Async Code
await Future.delayed(Duration(seconds: 1));
In Sync Code
import 'dart:io';
sleep(Duration(seconds:1));
Future.delayed(Duration(milliseconds: 100), () {
After milliseconds of 100
you will write function it will executes
});
// just to delay 500 miliSeconds
await Future.delayed(const Duration(milliseconds: 500));
Future.delayed(Duration(seconds: 2), () { // <-- Delay here
setState(() {
_isLoading = false; // <-- Code run after delay
});
});