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,38 +161,79 @@ class _SplashScreenState extends State<SplashScreen>
const SizedBox(height: 12), const SizedBox(height: 12),
// Message // Message
Text( Consumer<SplashProvider>(
message, builder: (context, splashProvider, _) {
textAlign: TextAlign.center, final statusText = splashProvider.isRefreshing
style: Theme.of( ? 'Clearing cache and preparing the latest version. '
context, 'This may take a few seconds...'
).textTheme.bodyMedium?.copyWith(color: Colors.grey.shade600), : message;
return Text(
statusText,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Colors.grey.shade600,
),
);
},
), ),
const SizedBox(height: 28), const SizedBox(height: 28),
// Refresh button // Refresh button
SizedBox( Consumer<SplashProvider>(
width: double.infinity, builder: (context, splashProvider, _) {
child: ElevatedButton( final refreshing = splashProvider.isRefreshing;
onPressed: () { return SizedBox(
provider.clearCacheAndRefresh(); width: double.infinity,
}, child: ElevatedButton(
style: ElevatedButton.styleFrom( onPressed: refreshing
backgroundColor: Colors.orange.shade700, ? null
foregroundColor: Colors.white, : () {
padding: const EdgeInsets.symmetric(vertical: 16), splashProvider.clearCacheAndRefresh();
shape: RoundedRectangleBorder( },
borderRadius: BorderRadius.circular(12), 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<Color>(
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,
),
),
),
), ),
], ],
), ),