init static method
Initialization API class
Implementation
static Future<void> init(
{required List<String> urls,
bool globalTestMode = false,
bool bearerToken = true,
disableAllTestMode = false,
bool enableUtf8Decoding = false,
bool loadTokenFromMemory = true,
String? authTitle,
bool usePrintInLogs = false,
Function(APIException error)? onAllError,
String? storageUrl}) async {
if (!DioApiST.instance.setInitState()) {
throw APIException(-1, body: 'API class already initialization');
}
if (urls.isEmpty) {
throw APIException(-1, body: 'URLs list is empty');
}
if (!urls[0].startsWith('http'))
throw APIException(-1, body: 'The url should start with https or http');
for (int i = 0; i < urls.length; i++) {
if (!urls[i].endsWith('/')) {
urls[i] += '/';
}
}
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('');
}
///Init new Version
if (authTitle != null) {
DioApiST.instance.setAuthTitle(authTitle);
}
DioApiST.instance.usePrint = usePrintInLogs;
DioApiST.instance.onAllError = onAllError;
DioApiST.instance.setBaseUrl(urls);
DioApiST.instance.setGlobalTestMode(globalTestMode);
DioApiST.instance.disableAllTestMode(disableAllTestMode);
DioApiST.instance.enableUtf8Decoding(enableUtf8Decoding);
DioApiST.instance.setBearerMode(bearerToken);
if (storageUrl != null) {
DioApiST.instance.setStorageUrl(storageUrl);
}
///Init OldVersion
if (authTitle != null) {
ApiST.instance.setAuthTitle(authTitle);
}
ApiST.instance.setUrls(urls);
ApiST.instance.setGlobalTestMode(globalTestMode);
ApiST.instance.disableAllTestMode(disableAllTestMode);
// ApiST.instance.enableUtf8Decoding(enableUtf8Decoding);
ApiST.instance.setBearerMode(bearerToken);
if (storageUrl != null) {
ApiST.instance.setStorageUrl(storageUrl);
}
}