App တစ်ခုမှာ data အားလုံးက ချက်ချင်းမရနိုင်ပါ။ API call, file read, database query, location request တွေက အချိန်ယူပါတယ်။ Dart မှာ Future က နောက်မှရလာမယ့် value ကိုကိုယ်စားပြုပါတယ်။ async/await က အချိန်ယူတဲ့ code ကို ဖတ်ရလွယ်အောင်ရေးပေးတဲ့ syntax ဖြစ်ပါတယ်။
dart
Future<String> fetchUserName() async {
await Future.delayed(const Duration(seconds: 2));
return 'Sai';
}
void main() async {
print('Loading user...');
final name = await fetchUserName();
print('Hello, $name');
}You should see
Console မှာ Loading user... ပေါ်ပြီး ၂ စက္ကန့်နောက်မှာ Hello, Sai ပေါ်ပါမယ်။နောက်တစ်ဆင့်
Async အခြေခံရပြီဆိုရင် HTTP package နဲ့ API data fetch လုပ်တာကိုလေ့လာပါ။