diff --git a/refilc_mobile_ui/lib/screens/login/kreten_login.dart b/refilc_mobile_ui/lib/screens/login/kreten_login.dart index 997a193d..7e10095e 100644 --- a/refilc_mobile_ui/lib/screens/login/kreten_login.dart +++ b/refilc_mobile_ui/lib/screens/login/kreten_login.dart @@ -45,6 +45,8 @@ class _KretenLoginWidgetState extends State String _errorMessage = ''; bool _hasTimedOut = false; Timer? _timeoutTimer; + int _autoRetryCount = 0; + static const int _maxAutoRetries = 1; static const _loginUrl = 'https://idp.e-kreta.hu/connect/authorize?prompt=login&nonce=wylCrqT4oN6PPgQn2yQB0euKei9nJeZ6_ffJ-VpSKZU&response_type=code&code_challenge_method=S256&scope=openid%20email%20offline_access%20kreta-ellenorzo-webapi.public%20kreta-eugyintezes-webapi.public%20kreta-fileservice-webapi.public%20kreta-mobile-global-webapi.public%20kreta-dkt-webapi.public%20kreta-ier-webapi.public&code_challenge=HByZRRnPGb-Ko_wTI7ibIba1HQ6lor0ws4bcgReuYSQ&redirect_uri=https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect&client_id=kreta-ellenorzo-student-mobile-ios&state=refilc_student_mobile'; @@ -110,6 +112,7 @@ class _KretenLoginWidgetState extends State } }); + _autoRetryCount = 0; _startTimeoutTimer(); }, onProgress: (progress) { @@ -141,6 +144,14 @@ class _KretenLoginWidgetState extends State if (!mounted) return; + // Auto-retry once on first error before showing the error UI, + // to handle transient network issues on initial load. + if (_autoRetryCount < _maxAutoRetries) { + _autoRetryCount++; + _retryLoad(); + return; + } + setState(() { _hasError = true; _errorMessage = error.description; @@ -165,6 +176,18 @@ class _KretenLoginWidgetState extends State }); } + void _retryLoad() { + setState(() { + _hasError = false; + _errorMessage = ''; + _hasTimedOut = false; + _initialPageLoaded = false; + loadingPercentage = 0; + }); + controller.loadRequest(Uri.parse(_loginUrl)); + _startTimeoutTimer(); + } + void _retry() { setState(() { _hasError = false; @@ -174,6 +197,7 @@ class _KretenLoginWidgetState extends State loadingPercentage = 0; _hasFadedIn = false; }); + _autoRetryCount = 0; _animationController.reset(); controller.loadRequest(Uri.parse(_loginUrl)); _startTimeoutTimer();