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;
Map<String, dynamic>? _updatePayload;
bool _isRefreshing = false;
SplashCheckStatus get status => _status;
Map<String, dynamic>? 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<void> clearCacheAndRefresh() async {
_isRefreshing = true;
notifyListeners();
try {
await _http.postRaw('/public/cache/cloudflare/clear');
} catch (_) {

View File

@@ -161,38 +161,79 @@ class _SplashScreenState extends State<SplashScreen>
const SizedBox(height: 12),
// Message
Text(
message,
textAlign: TextAlign.center,
style: Theme.of(
context,
).textTheme.bodyMedium?.copyWith(color: Colors.grey.shade600),
Consumer<SplashProvider>(
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<SplashProvider>(
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<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,
),
),
),
);
},
),
],
),