init method
void
init({
- String baseUrl = "",
- int connectTimeout = 30 * 1000,
- int receiveTimeout = 30 * 1000,
- String? pem,
- String? pKCSPath,
- String? pKCSPwd,
- String codeKey = '',
- String msgKey = '',
- String dataKey = '',
- String successCode = '',
- bool checkDataEmpty = true,
- ResponseType? responseType,
- bool openLog = true,
- int retry = 3,
- String? method,
- Map<
String, dynamic> ? headers, - Map<
String, dynamic> ? extra, - String? contentType,
- ValidateStatus? validateStatus,
- bool? followRedirects,
- Function? onError,
- Function? onFinish,
- Function? onStart,
- ValidateResponse? validateResponse,
- bool enableAutoCookie = false,
- ListFormat? listFormat,
- List<
String> ? publicErrorCode, - List<
Interceptor> ? interceptors,
初始化公共属性
baseUrl 地址前缀
connectTimeout 连接超时时间,毫秒
receiveTimeout 接收超时时间,毫秒
interceptors 基础拦截器
Implementation
void init({String baseUrl = "",
int connectTimeout = 30 * 1000,
int receiveTimeout = 30 * 1000,
String? pem,
String? pKCSPath,
String? pKCSPwd,
String codeKey = '',
String msgKey = '',
String dataKey = '',
String successCode = '',
bool checkDataEmpty = true,
ResponseType? responseType,
bool openLog = true,
int retry = 3,
String? method,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
String? contentType,
ValidateStatus? validateStatus,
bool? followRedirects,
Function? onError,
Function? onFinish,
Function? onStart,
ValidateResponse? validateResponse,
bool enableAutoCookie = false,
ListFormat? listFormat,
List<String>? publicErrorCode,
List<Interceptor>? interceptors
}) {
this._validateResponse = validateResponse;
this._onStart = onStart;
this._onError = onError;
this._onFinish = onFinish;
this._successCode = successCode;
this._codeKey = codeKey;
this._msgKey = msgKey;
this._dataKey = dataKey;
this._checkDataEmpty = checkDataEmpty;
this.openLog = openLog;
this.retry = retry;
this.pem = pem;
this.pKCSPath = pKCSPath;
this.interceptors = interceptors;
method = method??Method.post;
if(publicErrorCode != null){
this.publicErrorCode.addAll(publicErrorCode);
}
_baseOptions = BaseOptions(
baseUrl: baseUrl,
receiveTimeout: receiveTimeout,
connectTimeout: connectTimeout,
contentType: contentType,
responseType: responseType??ResponseType.json,
headers: headers??{},
extra: extra??{},
validateStatus: validateStatus,
followRedirects: followRedirects,
listFormat: listFormat,
method: method
);
_dio = createDio();
if(interceptors != null){
_dio.interceptors.addAll(interceptors);
}
}