connect method
Connect to server If error will be occured, NsgApiException will be generated
Implementation
Future connect(NsgBaseController controller) async {
if (!_initialized) await initialize();
var onRetry = controller.onRetry;
if (useNsgAuthorization && allowConnect && serverUri.isNotEmpty) {
var checkResult = await _checkVersion(onRetry);
if (checkResult == 2) {
NsgBaseController.showErrorByString('Application update required');
//TODO: сменить на диалог и запретить работу при наличии обязательного обновления
} else if (checkResult == 1) {
NsgBaseController.showErrorByString('A newer version is available. It is recommended to update the application');
}
if (token == '') {
await _anonymousLogin(onRetry);
} else {
try {
var result = await _checkToken(onRetry);
if (!result) {
debugPrint('CheckToken - Сервер отверг токен');
await _anonymousLogin(onRetry);
}
} on NsgApiException catch (e) {
if (e.error.errorType == null) {
} else {
rethrow;
}
await _anonymousLogin(onRetry);
}
}
}
await setLocale(languageCode: languageCode);
if (allowConnect && isAnonymous && loginRequired && serverUri.isNotEmpty) {
await openLoginPage().then((value) => controller.loadProviderData());
} else {
await controller.loadProviderData();
}
}