티스토리 뷰
http package
인터넷에서 데이터를 가지고 오기 위한 package로 api를 호출하여 데이터를 받아올 때 사용한다.
(https://pub.dev/packages/http)
http | Dart Package
A composable, multi-platform, Future-based API for HTTP requests.
pub.dev
http 사용법
1. pubspec.yaml 파일에 http dependencies 추가(https://pub.dev/packages/http/install)

2. 네트워크 연결을 위한 permission 추가 - 안드로이드 경우
2.1 android > app > src > main > AndroidManifest.xml 파일에 <user-permission> 추가

3. http 사용을 위한 import

4. get메소드를 사용하여 api 호출

http 호출로 받은 response
http로 호출로 response에는 아래와 같이 많은 정보를 포함하고 있다. 개발자가 필요한 값을 찾아 사용이 가능하다.
참고 : https://pub.dev/documentation/http/latest/http/Response-class.html
Response class - http library - Dart API
An HTTP response where the entire response body is known in advance. Inheritance Constructors Response(String body, int statusCode, {BaseRequest? request, bool isRedirect = false, bool persistentConnection = true, String? reasonPhrase}) Creates a new HTTP
pub.dev

dart:convert를 이용한 json data parse
1. json Data를 convert 하기 위하여 dart convert를 import 한다.

2. jsonDecode를 이용하여 response 받은 body의 정보를 json 형태로 변경

3. jsonDecode한 데이터에서 원하는 정보 추출하기


이번 내용도 코딩셰프 님의 강좌를 보고 직접 실습한 내용을 작성하였습니다.
감사합니다.
출처 및 참고 : https://youtu.be/ccq1yCmNzdk - 플러터(Flutter) 조금 매운맛🌶️ 강좌 14 | 날씨 앱(weather app) 만들기 2
'공부하는 키보드르륵 > Flutter' 카테고리의 다른 글
[Provider] 상태관리 (0) | 2024.03.21 |
---|---|
[날씨 App 만들기-3] data 전달 / json data 전달 (0) | 2022.10.31 |
[날씨 App 만들기-1] geolocator 사용하여 내 위치 찾기 (1) | 2022.10.24 |
[dart] List & Set & Map (1) | 2022.10.06 |
[dart] loop (0) | 2022.10.06 |
- Total
- Today
- Yesterday
- 정보처리기사
- 소근육발달
- 코딩셰프
- Spring
- 개발자
- 행운
- 난임부부
- 반응형레이아웃
- springboot
- java
- DART
- Spring cloud gateway
- spring msa
- EUREKA
- MSA
- 육아
- apigateway
- json
- 로또
- android
- 갤럭시s25울트라
- 내돈내산
- 인생역전
- 로또구매팁
- 인프런
- Flutter
- 코드팩토리
- 안드로이드
- 실내데이트
- 플러터
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |