fixing splash screen

This commit is contained in:
Prince
2026-06-21 20:27:45 +02:00
parent 101486cb1e
commit eca22cd6a3
2 changed files with 73 additions and 27 deletions

View File

@@ -12,9 +12,11 @@ class SplashProvider extends ChangeNotifier {
SplashCheckStatus _status = SplashCheckStatus.checking; SplashCheckStatus _status = SplashCheckStatus.checking;
Map<String, dynamic>? _updatePayload; Map<String, dynamic>? _updatePayload;
bool _isRefreshing = false;
SplashCheckStatus get status => _status; SplashCheckStatus get status => _status;
Map<String, dynamic>? get updatePayload => _updatePayload; Map<String, dynamic>? get updatePayload => _updatePayload;
bool get isRefreshing => _isRefreshing;
/// The store / download URL from the server payload, or `null` if /// The store / download URL from the server payload, or `null` if
/// the server didn't include one. /// 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 /// 3. Performs a hard refresh by reloading the current URL, which
/// forces the browser to re-fetch all cached assets. /// forces the browser to re-fetch all cached assets.
Future<void> clearCacheAndRefresh() async { Future<void> clearCacheAndRefresh() async {
_isRefreshing = true;
notifyListeners();
try { try {
await _http.postRaw('/public/cache/cloudflare/clear'); await _http.postRaw('/public/cache/cloudflare/clear');
} catch (_) { } catch (_) {

View File

@@ -161,31 +161,70 @@ class _SplashScreenState extends State<SplashScreen>
const SizedBox(height: 12), const SizedBox(height: 12),
// Message // Message
Text( Consumer<SplashProvider>(
message, 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, textAlign: TextAlign.center,
style: Theme.of( style: Theme.of(context).textTheme.bodyMedium?.copyWith(
context, color: Colors.grey.shade600,
).textTheme.bodyMedium?.copyWith(color: Colors.grey.shade600), ),
);
},
), ),
const SizedBox(height: 28), const SizedBox(height: 28),
// Refresh button // Refresh button
SizedBox( Consumer<SplashProvider>(
builder: (context, splashProvider, _) {
final refreshing = splashProvider.isRefreshing;
return SizedBox(
width: double.infinity, width: double.infinity,
child: ElevatedButton( child: ElevatedButton(
onPressed: () { onPressed: refreshing
provider.clearCacheAndRefresh(); ? null
: () {
splashProvider.clearCacheAndRefresh();
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange.shade700, backgroundColor: Colors.orange.shade700,
foregroundColor: Colors.white, foregroundColor: Colors.white,
disabledBackgroundColor: Colors.orange.shade400,
disabledForegroundColor: Colors.white70,
padding: const EdgeInsets.symmetric(vertical: 16), padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
), ),
), ),
child: const Text( child: refreshing
? const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white,
),
),
),
SizedBox(width: 12),
Text(
'Refreshing...',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
],
)
: const Text(
'Refresh to Update', 'Refresh to Update',
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
@@ -193,6 +232,8 @@ class _SplashScreenState extends State<SplashScreen>
), ),
), ),
), ),
);
},
), ),
], ],
), ),