[Dart] Futures, Async & Await

 

 

[Ko]

 - Future return하는 함수의 body 앞에는 Async 붙이고, Future return하는 해당 code 앞에는 await 붙임.

 

* Stateful Widget Lifecycle Methods

 - return되는 Future 받아서 사용하려면, Future return하는 method 앞에 await 붙이고, return 받는 Future variable 저장해서 사용함.

  Position position = await Geolocator()

      .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);

 -  코드에서 await 붙이지 않으면 Future<Position> position = Geo…. 실제 완료된 position 아닌 Position Future 받게됨.

 

[En]

-Async is added to the body of the function that returns the Future, and await is added to the code that returns the Future.


* Stateful Widget Lifecycle Methods
  - To receive and use the returned Future, add await in front of the method that returns the Future, and use the stored Future as a variable.
  Position position = await Geolocator ()
      .getCurrentPosition (desiredAccuracy: LocationAccuracy.high);
 - If you don't add await in the code above, Future  position = Geo… . Receive the Future of Position, not the actual completed position.

'플러터(Flutter) > 다트(Dart)' 카테고리의 다른 글

[Dart] list combine method  (0) 2020.04.17
[Dart] Exception Handling & Null Aware Operators  (0) 2020.03.19
[Dart] Maps  (0) 2020.03.19
[Dart] Functions as First Order Objects  (0) 2020.03.19
[Dart] Enums  (0) 2020.03.19

+ Recent posts