-
[Flutter]Future Await Async웹 and 앱 프로그래밍/Flutter 2022. 12. 24. 20:42
Flutter에서 비동기 프로그램을 짜기 위해서는 비동기 함수를 표시해 주는 Async 그리고 비동기 사용 위한 Await, 지금은 없지만 미래에 (값을) 받게 해주는 Future가 존재한다.
EX)
Future<String> postReply(VALUE) async { Map<String,String> ask={'VALUE':VALUE}; final uri = Uri.https('example.com', 'api/fetch'/*,만약 get 사용시 파라미터지정가능{'limit': '10'}*/); final response = await http.post( uri, headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body: ask , ); }
또한 이값을 나중에 받고 나중에 사용하기위해서 .then을 사용할수있다
postReply(VALUE).then((value){ //함수가 끝나고(return 하고 난 후) 리턴 한 값을 value로 받아주고 다음에 할 코드를 적을 수 있다. logger.wtf(value); })
자바스크립트의 Promise를 생각하면 편하다.
'웹 and 앱 프로그래밍 > Flutter' 카테고리의 다른 글
[Flutter] Main함수를 비동기 선언시 (0) 2022.12.28 [Flutter] () => 란 (0) 2022.12.25 [Flutter]크롤링 중 한글이 이상할 때 EX) (0) 2022.12.24 [Flutter]Scaffold (0) 2022.12.24 [Flutter]URI함수 (1) 2022.12.24