Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:async';
- /**
- *
- * Learning Dart Language
- *
- * Basic Example async/await
- *
- * @author bwnyasse
- *
- */
- void createOrderMessage () async {
- print("En attente de votre demande ...");
- var order = await getUserOrder();
- print('Votre demande est : $order');
- }
- Future<String> getUserOrder() {
- // Imagine that this function is more complex and slow.
- return Future.delayed(Duration(seconds: 4), () => 'Une formation Dart & Flutter ');
- }
- main() async {
- countSeconds(4);
- await createOrderMessage();
- }
- // You can ignore this function - it's here to visualize delay time in this example.
- void countSeconds(s) {
- for( var i = 1 ; i <= s; i++ ) {
- Future.delayed(Duration(seconds: i), () => print(i));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement