Future.delayed(Duration(milliseconds: 100), () {
// Do something
});
Timer(Duration(seconds: 5), () {
print(" This line is execute after 5 seconds");
});
Future.delayed(const Duration(milliseconds: 500), () {
// Here you can write your code
setState(() {
// Here you can write your code for open new view
});
});
// just to delay 500 miliSeconds
await Future.delayed(const Duration(milliseconds: 500));
void main() async {
print('Started at ${DateTime.now()}');
final time = await Future.delayed(Duration(seconds: 2)).then((value) => DateTime.now());
print('Awaited time was at $time');
}
In Async Code
await Future.delayed(Duration(seconds: 1));
In Sync Code
import 'dart:io';
sleep(Duration(seconds:1));
Future.delayed(Duration(seconds: 2), () { // <-- Delay here
setState(() {
_isLoading = false; // <-- Code run after delay
});
});
Future.delayed(Duration(milliseconds: 100), () {
After milliseconds of 100
you will write function it will executes
});
Future myFuture() async {
await new Future.delayed(new Duration(seconds: 3));
//return your_main_future_code_here;
}