From eca22cd6a349702ac9b6ae84b263ed6829a4a410 Mon Sep 17 00:00:00 2001 From: Prince Date: Sun, 21 Jun 2026 20:27:45 +0200 Subject: [PATCH] fixing splash screen --- lib/providers/splash_provider.dart | 5 ++ lib/screens/splash_screen.dart | 95 +++++++++++++++++++++--------- 2 files changed, 73 insertions(+), 27 deletions(-) diff --git a/lib/providers/splash_provider.dart b/lib/providers/splash_provider.dart index 09e63cb..2e00329 100644 --- a/lib/providers/splash_provider.dart +++ b/lib/providers/splash_provider.dart @@ -12,9 +12,11 @@ class SplashProvider extends ChangeNotifier { SplashCheckStatus _status = SplashCheckStatus.checking; Map? _updatePayload; + bool _isRefreshing = false; SplashCheckStatus get status => _status; Map? get updatePayload => _updatePayload; + bool get isRefreshing => _isRefreshing; /// The store / download URL from the server payload, or `null` if /// the server didn't include one. @@ -59,6 +61,9 @@ class SplashProvider extends ChangeNotifier { /// 3. Performs a hard refresh by reloading the current URL, which /// forces the browser to re-fetch all cached assets. Future clearCacheAndRefresh() async { + _isRefreshing = true; + notifyListeners(); + try { await _http.postRaw('/public/cache/cloudflare/clear'); } catch (_) { diff --git a/lib/screens/splash_screen.dart b/lib/screens/splash_screen.dart index 88ddc48..30e711c 100644 --- a/lib/screens/splash_screen.dart +++ b/lib/screens/splash_screen.dart @@ -161,38 +161,79 @@ class _SplashScreenState extends State const SizedBox(height: 12), // Message - Text( - message, - textAlign: TextAlign.center, - style: Theme.of( - context, - ).textTheme.bodyMedium?.copyWith(color: Colors.grey.shade600), + Consumer( + builder: (context, splashProvider, _) { + final statusText = splashProvider.isRefreshing + ? 'Clearing cache and preparing the latest version. ' + 'This may take a few seconds...' + : message; + return Text( + statusText, + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.bodyMedium?.copyWith( + color: Colors.grey.shade600, + ), + ); + }, ), const SizedBox(height: 28), // Refresh button - SizedBox( - width: double.infinity, - child: ElevatedButton( - onPressed: () { - provider.clearCacheAndRefresh(); - }, - style: ElevatedButton.styleFrom( - backgroundColor: Colors.orange.shade700, - foregroundColor: Colors.white, - padding: const EdgeInsets.symmetric(vertical: 16), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), + Consumer( + builder: (context, splashProvider, _) { + final refreshing = splashProvider.isRefreshing; + return SizedBox( + width: double.infinity, + child: ElevatedButton( + onPressed: refreshing + ? null + : () { + splashProvider.clearCacheAndRefresh(); + }, + style: ElevatedButton.styleFrom( + backgroundColor: Colors.orange.shade700, + foregroundColor: Colors.white, + disabledBackgroundColor: Colors.orange.shade400, + disabledForegroundColor: Colors.white70, + padding: const EdgeInsets.symmetric(vertical: 16), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + ), + child: refreshing + ? const Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox( + width: 20, + height: 20, + child: CircularProgressIndicator( + strokeWidth: 2, + valueColor: AlwaysStoppedAnimation( + Colors.white, + ), + ), + ), + SizedBox(width: 12), + Text( + 'Refreshing...', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + ), + ), + ], + ) + : const Text( + 'Refresh to Update', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + ), + ), ), - ), - child: const Text( - 'Refresh to Update', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - ), - ), - ), + ); + }, ), ], ),