-
[Flutter] Rest API (Dio)Flutter 2022. 2. 15. 19:53
1. 패키지 참조 (pubspec.yaml)
dependencies: dio: ^4.0.4
import 'package:dio/dio.dart';
Method - GET
TextButton( onPressed: () async { var result = await Dio().get( "http://localhost:3000/organization", queryParameters: { "country": "Honduras" }); print(result.data.toString()); }, child: const Text("GET") ),
Method - POST
TextButton( onPressed: () async { var result = await Dio().post( "http://localhost:3000/admin/login-admin", data: '{ "Id" : "admin", "Pw" : "admin"}'); print(result.data.toString()); }, child: const Text("POST")),
Method - PUT
TextButton( onPressed: () async { var result = await Dio().put( "http://localhost:3000/admin/login-admin", data: '{ "Id" : "admin", "Pw" : "admin"}'); print(result.data.toString()); }, child: const Text("PUT")),
Method - DELETE
TextButton( onPressed: () async { var result = await Dio().delete( "http://localhost:3000/organization", queryParameters: { "category": "Other State", }); print(result.data.toString()); }, child: const Text("DELETE")),
'Flutter' 카테고리의 다른 글
[Flutter] SnackBar (0) 2021.12.31 [Flutter] vscode 확장프로그램 (0) 2021.12.29