request function
发送请求并解析远程服务器返回的result对应的实体类型
baseUrl: 主机地址 path: 请求路径 data: 请求参数 connectTimeout: 超时时间 validResult: 是否检验返回结果 autoLoading: 展示Loading
Implementation
Future<Result> request(
{String? baseUrl,
String path = '',
data,
Map<String, dynamic>? queryParameters,
Options? options,
int? connectTimeout,
bool validResult = true,
bool autoLoading = false}) async {
if (autoLoading) {
showLoading();
}
Session session = Session(
config: Config(
baseUrl:
baseUrl?.isNotEmpty == true ? baseUrl! : _session.config.baseUrl,
proxy: _session.config.proxy,
badCertificateCallback: _session.config.badCertificateCallback,
connectTimeout: _session.config.connectTimeout,
receiveTimeout: _session.config.receiveTimeout,
code: _session.config.code,
data: _session.config.data,
list: _session.config.list,
message: _session.config.message,
validCode: _session.config.validCode,
errorTimeout: _session.config.errorTimeout,
errorResponse: _session.config.errorResponse,
errorCancel: _session.config.errorCancel,
errorOther: _session.config.errorOther),
onRequest: _session.onRequest,
onResult: validResult ? _session.onResult : null);
Result result = await session.request(
path,
data: data,
queryParameters: queryParameters,
options: options,
connectTimeout: connectTimeout,
);
if (autoLoading) {
dismissLoading();
}
return _onResult != null ? _onResult!(result, validResult) : result;
}