Thứ Tư, 18 tháng 9, 2019
await and Future.delayed trong flutter
void createOrderMessage () async {
print('Run createOrderMessage...');
var order = await getUserOrder();
print('Your order is: $order');
}
Future<String> getUserOrder() {
// Imagine that this function is more complex and slow.
return Future.delayed(Duration(seconds: 30), () => 'Large Latte');
}
main() async {
await createOrderMessage();
countSeconds(4);
}
// You can ignore this function - it's here to visualize delay time in this example.
void countSeconds(s) {
print('Run countSeconds()...');
for( var i = 1 ; i <= s; i++ ) {
Future.delayed(Duration(seconds: i), () => print(i));
}
}
Ket Qua :
Run createOrderMessage... Your order is: Large Latte Run countSeconds()... 1 2 3 4
Đăng ký:
Đăng Nhận xét (Atom)
How to reload app in flutter
Phoenix . rebirth (context);
-
Wrap( children: [ MyWidget(), MyWidget(), MyWidget(), MyWidget(), MyWidget(), ], ),
-
FocusScope . of ( context ). requestFocus ( FocusNode ());
-
double d = 20.5 ; int i = d . toInt (); // i = 20 int i = d . round (); // i = 21 int i = d . ceil (); // i = 21 int i = ...
Không có nhận xét nào:
Đăng nhận xét