init static method

Future<void> init({
  1. required String baseUrl,
  2. bool globalTestMode = false,
  3. bool bearerToken = true,
  4. dynamic disableAllTestMode = false,
  5. bool enableUtf8Decoding = false,
  6. bool loadTokenFromMemory = true,
  7. String? authTitle,
  8. String? storageUrl,
})

Initialization API class

Implementation

static Future<void> init(
    {required String baseUrl,
    bool globalTestMode = false,
    bool bearerToken = true,
    disableAllTestMode = false,
    bool enableUtf8Decoding = false,
    bool loadTokenFromMemory = true,
    String? authTitle,
    String? storageUrl}) async {
  if (!ApiST.instance.setInitState()) {
    throw EticonApiError(error: 'API class already initialization');
  }
  if (baseUrl.isEmpty) {
    throw EticonApiError(error: 'URL is empty');
  }
  if (!baseUrl.startsWith('http')) throw EticonApiError(error: 'The url should start with https or http');
  if (baseUrl[baseUrl.length - 1] != '/') baseUrl += '/';
  await GetStorage.init();

  ///LoadTokenFromMemory now here
  if (loadTokenFromMemory) {
    String token = GetStorage().read('ApiEticonMainAuthToken2312') ?? '';
    if (token.isNotEmpty) {
      Token.instance.setToken(token);
    }
    token = GetStorage().read('ApiEticonMainRefreshToken2312') ?? '';
    if (token.isNotEmpty) {
      Token.instance.setRefreshToken(token);
    }
    String expireTimeString = GetStorage().read('ApiEticonMainExpireDate2312') ?? '';
    if(expireTimeString.isNotEmpty){
    DateTime expireTime = DateTime.parse(GetStorage().read('ApiEticonMainExpireDate2312'));
      Token.instance.expireDate = expireTime;
    }
  } else {
    Token.instance.setToken('');
    Token.instance.setRefreshToken('');
  }
  if (authTitle != null) {
    ApiST.instance.setAuthTitle(authTitle);
  }
  ApiST.instance.setBaseUrl(baseUrl);
  ApiST.instance.setGlobalTestMode(globalTestMode);
  ApiST.instance.disableAllTestMode(disableAllTestMode);
  ApiST.instance.enableUtf8Decoding(enableUtf8Decoding);
  ApiST.instance.setBearerMode(bearerToken);
  if (storageUrl != null) {
    ApiST.instance.setStorageUrl(storageUrl);
  }
}