1、首先在pubspec.yaml中引入
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dio: ^4.0.0
2、下面为测试代码
import 'dart:convert';
import 'dart:html';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
void getHttp() async {
var dio = Dio();
dio.interceptors.add(LogInterceptor(responseBody: true));
dio.options.baseUrl = '填写要请求的网址';
dio.options.headers = {'contentType': 'application/json'};
var response = await dio.post(
'',
data: {
"account": "account",
"password": "password"
},
options: Options(
contentType: Headers.jsonContentType,
),
);
Map<String, dynamic> resCall = response.data;
print(resCall['data']['token']);
}
void main() async {
getHttp();
}
3、对于response解析也可以用这种方法
var res = json.decode(response.toString());
print(res['data']['token']);