插件依赖导入
# 基于dio的网络请求日志
dio_log: ^1.3.3
报错
Because dio_log >=1.3.3 depends on dio ^3.0.0 and fluttersteven depends on dio ^2.1.2, dio_log >=1.3.3 is forbidden.
So, because fluttersteven depends on dio_log ^1.3.3, version solving failed.
pub get failed (1; So, because fluttersteven depends on dio_log ^1.3.3, version solving failed.)
注意
此版本要求dio的版本号要大于dio ^3.0.0
使用
1.给dio设置监听
dio.interceptors.add(DioLogInterceptor());
2.在你的主页面添加全局的悬浮按钮,用于跳转日志列表
///display overlay button 显示悬浮按钮
showDebugBtn(context);
///cancel overlay button 取消悬浮按钮
dismissDebugBtn();
///overlay button state of display 悬浮按钮展示状态
debugBtnIsShow()
3.或者在你期望的地方打开日志列表
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => HttpLogListWidget(),
),
);
4.其他可设置参数
/// Sets the maximum number of entries for logging 设置记录日志的最大条数
LogPoolManager.getInstance().maxCount = 100;
例如Example
_dio.interceptors
.add(InterceptorsWrapper(onRequest: (RequestOptions options) {
print(
"\n================================= 请求数据 =================================");
print("method = ${options.method.toString()}");
print("url = ${options.uri.toString()}");
print("headers = ${options.headers}");
print("params = ${options.queryParameters}");
}, onResponse: (Response response) {
print(
"\n================================= 响应数据开始 =================================");
print("code = ${response.statusCode}");
print("data = ${response.data}");
print(
"================================= 响应数据结束 =================================\n");
}, onError: (DioError e) {
print(
"\n=================================错误响应数据 =================================");
print("type = ${e.type}");
print("message = ${e.message}");
print("stackTrace = ${e.stackTrace}");
print("\n");
}));
网友评论