File tree Expand file tree Collapse file tree 2 files changed +24
-16
lines changed Expand file tree Collapse file tree 2 files changed +24
-16
lines changed Original file line number Diff line number Diff line change 11class Config {
2+
3+ // Private constructor to prevent instantiation
4+ Config ._();
5+
26 static bool ? DEBUG = true ;
37
48
Original file line number Diff line number Diff line change @@ -15,23 +15,24 @@ import 'package:gsy_github_app_flutter/common/net/result_data.dart';
1515class HttpManager {
1616 static const CONTENT_TYPE_JSON = "application/json" ;
1717 static const CONTENT_TYPE_FORM = "application/x-www-form-urlencoded" ;
18-
19- final Dio _dio = Dio (); // 使用默认配置
20-
21- final TokenInterceptors _tokenInterceptors = TokenInterceptors ();
22-
23- HttpManager () {
24- _dio.interceptors.add (HeaderInterceptors ());
25-
26- _dio.interceptors.add (_tokenInterceptors);
27-
28- _dio.interceptors.add (LogsInterceptors ());
29-
30- _dio.interceptors.add (ErrorInterceptors ());
31-
32- _dio.interceptors.add (ResponseInterceptors ());
18+ late final Dio _dio;
19+ late final TokenInterceptors _tokenInterceptors;
20+
21+ HttpManager ._internal () {
22+ _dio = Dio (); // 使用默认配置
23+ _tokenInterceptors = TokenInterceptors ();
24+
25+ _dio.interceptors.addAll ([
26+ HeaderInterceptors (),
27+ _tokenInterceptors,
28+ LogsInterceptors (),
29+ ErrorInterceptors (),
30+ ResponseInterceptors (),
31+ ]);
3332 }
3433
34+ static final HttpManager _instance = HttpManager ._internal ();
35+
3536 ///发起网络请求
3637 ///[ url] 请求url
3738 ///[ params] 请求参数
@@ -91,6 +92,9 @@ class HttpManager {
9192 getAuthorization () async {
9293 return _tokenInterceptors.getAuthorization ();
9394 }
95+
96+ /// 提供单例访问
97+ static HttpManager get instance => _instance;
9498}
9599
96- final HttpManager httpManager = HttpManager () ;
100+ final HttpManager httpManager = HttpManager .instance ;
You can’t perform that action at this time.
0 commit comments