Skip to content

Commit 7ec7c70

Browse files
committed
add some code
1 parent 39e5552 commit 7ec7c70

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

lib/common/net/api.dart

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import 'package:gsy_github_app_flutter/common/net/code.dart';
33

44
import 'dart:collection';
55

6+
//import 'package:connectivity_plus/connectivity_plus.dart';
7+
68
import 'package:gsy_github_app_flutter/common/net/interceptors/error_interceptor.dart';
79
import 'package:gsy_github_app_flutter/common/net/interceptors/header_interceptor.dart';
810
import 'package:gsy_github_app_flutter/common/net/interceptors/log_interceptor.dart';
@@ -58,10 +60,11 @@ class HttpManager {
5860
if (e.response != null) {
5961
errorResponse = e.response;
6062
} else {
61-
errorResponse = Response(statusCode: 666, requestOptions: RequestOptions(path: url));
63+
errorResponse = Response(
64+
statusCode: 666, requestOptions: RequestOptions(path: url));
6265
}
6366
if (e.type == DioExceptionType.connectionTimeout ||
64-
e.type == DioExceptionType.sendTimeout ||
67+
e.type == DioExceptionType.sendTimeout ||
6568
e.type == DioExceptionType.receiveTimeout) {
6669
errorResponse!.statusCode = Code.NETWORK_TIMEOUT;
6770
}
@@ -98,3 +101,48 @@ class HttpManager {
98101
}
99102

100103
final HttpManager httpManager = HttpManager.instance;
104+
105+
//
106+
//
107+
// initDio() {
108+
// DioClient.getInstance();
109+
// initializeNetworkListener();
110+
// }
111+
//
112+
// class DioClient {
113+
// static Dio? _dio;
114+
//
115+
// DioClient._();
116+
//
117+
// static Future<Dio> getInstance() async {
118+
// if (_dio == null) {
119+
// await _initialize();
120+
// }
121+
// return _dio!;
122+
// }
123+
//
124+
// static Future<void> _initialize() async {
125+
// _dio = Dio(BaseOptions(
126+
// connectTimeout: const Duration(seconds: 10),
127+
// receiveTimeout: const Duration(seconds: 10),
128+
// ));
129+
//
130+
// _dio!.interceptors.add(LogInterceptor(
131+
// requestHeader: true,
132+
// requestBody: true,
133+
// responseHeader: true,
134+
// responseBody: true,
135+
// ));
136+
// }
137+
//
138+
// static void reset() {
139+
// _dio?.close();
140+
// _dio = null;
141+
// }
142+
// }
143+
//
144+
// void initializeNetworkListener() {
145+
// Connectivity().onConnectivityChanged.listen((result) {
146+
// DioClient.reset();
147+
// });
148+
// }

0 commit comments

Comments
 (0)