init static method

Future<ApiService> init({
  1. required String baseUrl,
  2. bool needToShowLog = false,
  3. bool needToLogRequests = false,
  4. NetworkMonitoringFunction? networkMonitoringFunction,
  5. int? unauthorizedStatusCode = 401,
  6. void onUnauthorizedCallBack()?,
  7. bool needInitialGlobalInstance = true,
})

Must be called before using instance or request. Example:

await ApiService.init(baseUrl: "https://api.example.com");

Implementation

static Future<ApiService> init({
  required String baseUrl,
  bool needToShowLog = false,
  bool needToLogRequests = false,
  // unauthorized callback
  NetworkMonitoringFunction? networkMonitoringFunction,
  int? unauthorizedStatusCode = 401,
  void Function()? onUnauthorizedCallBack,
  bool needInitialGlobalInstance = true,
}) async {
  final service = ApiService._internal();
  await service.initConfig(
    baseUrl: baseUrl,
    needToShowLog: needToShowLog,
    needToLogRequests: needToLogRequests,
    networkMonitoringFunction: networkMonitoringFunction,
    unauthorizedStatusCode: unauthorizedStatusCode,
    onUnauthorizedCallBack: onUnauthorizedCallBack,
  );
  if (needInitialGlobalInstance) {
    _instance = service;
  }
  return service;
}