NetworkConfig class
网络配置
Constructors
-
NetworkConfig({required String baseUrl, Duration connectTimeout = const Duration(seconds: 30), Duration receiveTimeout = const Duration(seconds: 30), DataParser? parser, Map<
String, dynamic> ? headers, void onError(NetworkException)?, FutureOr<void> onUnauthorized(NetworkException)?, CacheStrategyType cacheStrategyType = CacheStrategyType.memory, TokenFormatConfig? tokenFormatConfig, bool enableTokenInterceptor = true, bool enableConnectivityInterceptor = true, bool enableResponseInterceptor = true, ResponseDataConfig? responseInterceptorConfig, bool enableErrorInterceptor = true, ErrorMessageConfig? errorInterceptorConfig, bool? enableLoggerInterceptor, LoggerConfig? loggerConfig})
Properties
- baseUrl → String
-
基础URL
final
- cacheStrategyType → CacheStrategyType
-
缓存策略类型
final
- connectTimeout → Duration
-
连接超时
final
- enableConnectivityInterceptor → bool
-
是否启用连通性拦截器(检查网络连接)
final
- enableErrorInterceptor → bool
-
是否启用错误拦截器
final
- enableLoggerInterceptor → bool?
-
是否启用日志拦截器
如果为null,则根据编译模式自动判断(debug模式启用,release模式禁用)
final
- enableResponseInterceptor → bool
-
是否启用响应拦截器(统一响应数据格式)
final
- enableTokenInterceptor → bool
-
是否启用Token拦截器,默认为true
final
- errorInterceptorConfig → ErrorMessageConfig?
-
错误拦截器配置
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
headers
→ Map<
String, dynamic> ? -
默认Headers
final
- loggerConfig → LoggerConfig?
-
日志拦截器配置
final
- onError → void Function(NetworkException)?
-
错误处理器
final
-
401未授权处理器
当收到401响应时,会优先调用此处理器
final
- parser → DataParser?
-
默认数据解析器
如果设置了此解析器,所有请求默认使用此解析器解析响应数据
final
- receiveTimeout → Duration
-
接收超时
final
- responseInterceptorConfig → ResponseDataConfig?
-
响应拦截器配置
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shouldEnableLoggerInterceptor → bool
-
获取是否启用日志拦截器
如果enableLoggerInterceptor为null,则根据LoggerConfig的enabled判断
如果LoggerConfig也为null,则创建一个默认配置,使用其默认行为(debug模式启用,release模式禁用)
no setter
- tokenFormatConfig → TokenFormatConfig?
-
Token格式化配置
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited