init static method

void init({
  1. int timeout = 15,
  2. String baseUrl = "",
  3. String? codeField,
  4. String? dataField,
  5. String? msgField,
  6. String? successCode,
  7. String? tokenHeaderName,
  8. Function? tokenCreator,
  9. Map<String, dynamic>? header,
  10. dynamic onHookResponse(
    1. dynamic
    )?,
})

Implementation

static void init({
  int timeout = 15,
  String baseUrl = "",
  String? codeField,
  String? dataField,
  String? msgField,
  String? successCode,
  String? tokenHeaderName ,
  Function? tokenCreator,
  Map<String, dynamic>? header,
  Function(dynamic)? onHookResponse,
}) {
  _dio ??= Dio();
  _dio!.options.sendTimeout = Duration(seconds: timeout);
  _dio!.options.connectTimeout = Duration(seconds: timeout);
  _dio!.options.receiveTimeout = Duration(seconds: timeout);
  _dio!.options.baseUrl = baseUrl;
  _dio!.interceptors.add(HttpFormatter());
  _dio!.interceptors.add(TokenInterceptor(tokenHeaderName ?? _tokenHeader, tokenCreator, onHookResponse: onHookResponse));
  if(ObjectUtil.isNotEmpty(codeField)) _codeField = codeField!;
  if(ObjectUtil.isNotEmpty(dataField)) _dataField = dataField!;
  if(ObjectUtil.isNotEmpty(msgField)) _msgField = msgField!;
  if(ObjectUtil.isNotEmpty(successCode)) _successCode = successCode!;
  if(header!=null) _dio?.options.headers.addAll(header);
}