Slide 6
Slide 6 text
Future
void main() async {
final uncompleted = futureFunction1();
print("uncompleted: $uncompleted");
final completedWithData = await futureFunction1();
print("completedWithData: $completedWithData");
final completedWithError = await futureFunction2();
print("completedWithError: $completedWithError");
}
Future futureFunction1() async {
return await Future.delayed(
const Duration(seconds: 1),
() {
return true;
},
);
}
Future futureFunction2() async {
return await Future.delayed(
const Duration(seconds: 1),
() {
throw "Terjadi kesalahan";
},
);
}