bug fix on batches for zesa

This commit is contained in:
Prince
2026-06-21 00:24:36 +02:00
parent 381b5fbf08
commit b90d95bc63
11 changed files with 389 additions and 40 deletions

View File

@@ -1,6 +1,10 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:gif_view/gif_view.dart';
import 'package:provider/provider.dart';
import 'package:qpay/providers/splash_provider.dart';
import 'package:qpay/routes.dart';
import 'package:url_launcher/url_launcher.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@@ -16,6 +20,8 @@ class _SplashScreenState extends State<SplashScreen>
late Animation<double> _fadeAnimation;
late Animation<double> _scaleAnimation;
bool _bottomSheetShown = false;
@override
void initState() {
super.initState();
@@ -40,8 +46,28 @@ class _SplashScreenState extends State<SplashScreen>
CurvedAnimation(parent: _scaleController, curve: Curves.elasticOut),
);
// Start animations
// Start animations and version check
_startAnimations();
// Kick off the version check via the provider (mounted-checked
// inside a post-frame callback so the widget is in the tree).
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
context.read<SplashProvider>().addListener(_onStatusChanged);
context.read<SplashProvider>().checkVersion();
}
});
}
void _onStatusChanged() {
if (!mounted) return;
final provider = context.read<SplashProvider>();
if (provider.status == SplashCheckStatus.updateAvailable) {
_showUpdateBottomSheet();
}
// For noUpdate we do nothing here — the animation will call
// splashState.finish() when it completes naturally.
}
void _startAnimations() async {
@@ -50,16 +76,20 @@ class _SplashScreenState extends State<SplashScreen>
_fadeController.forward();
_scaleController.forward();
// Wait for 3 seconds (adjust as needed)
// Let the splash branding play for at least 1.25 s.
await Future.delayed(const Duration(milliseconds: 1250));
// Start fade out animation
await _fadeController.reverse();
// Mark splash complete so GoRouter redirect releases navigation
// to the originally intended route (e.g. /poll/:id).
// After the animation completes, release navigation to the
// originally intended route UNLESS an update is available
// (in which case the bottom sheet keeps the user on splash).
if (mounted) {
splashState.finish();
final provider = context.read<SplashProvider>();
if (provider.status != SplashCheckStatus.updateAvailable) {
splashState.finish();
}
}
} catch (e) {
// If there's an error, still complete the splash screen
@@ -69,8 +99,208 @@ class _SplashScreenState extends State<SplashScreen>
}
}
void _showUpdateBottomSheet() {
// Prevent showing the sheet more than once.
if (_bottomSheetShown) return;
_bottomSheetShown = true;
final provider = context.read<SplashProvider>();
final payload = provider.updatePayload;
final version = payload?['version']?.toString() ?? 'a newer';
if (kIsWeb) {
_showWebUpdateSheet(provider, version);
} else {
_showMobileUpdateSheet(provider, version);
}
}
/// Web: clear Cloudflare cache, wait 5 s, then hard-refresh the page
/// so the browser picks up the new deployment.
void _showWebUpdateSheet(SplashProvider provider, String version) {
final message =
'A new version of the app is available. Please refresh to get the latest update.';
showModalBottomSheet(
context: context,
isDismissible: false,
enableDrag: false,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
),
builder: (sheetContext) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Icon
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.orange.shade50,
shape: BoxShape.circle,
),
child: Icon(
Icons.system_update_rounded,
color: Colors.orange.shade700,
size: 40,
),
),
const SizedBox(height: 20),
// Title
Text(
'Update Available',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 12),
// Message
Text(
message,
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),
),
),
child: const Text(
'Refresh to Update',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
),
],
),
),
);
},
);
}
/// Mobile (Android / iOS): open the app store / download URL so the
/// user can install the latest version. No cache clearing needed.
void _showMobileUpdateSheet(SplashProvider provider, String version) {
final message =
provider.updatePayload?['message']?.toString() ??
'A new version of the app is available. Please download the latest version from the store.';
final downloadUrl = provider.downloadUrl;
showModalBottomSheet(
context: context,
isDismissible: false,
enableDrag: false,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
),
builder: (sheetContext) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Icon
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.orange.shade50,
shape: BoxShape.circle,
),
child: Icon(
Icons.system_update_rounded,
color: Colors.orange.shade700,
size: 40,
),
),
const SizedBox(height: 20),
// Title
Text(
'Update Available',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 12),
// Message
Text(
'Version $version is now available. $message',
textAlign: TextAlign.center,
style: Theme.of(
context,
).textTheme.bodyMedium?.copyWith(color: Colors.grey.shade600),
),
const SizedBox(height: 28),
// Download button
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
if (downloadUrl != null && downloadUrl.isNotEmpty) {
launchUrl(
Uri.parse(downloadUrl),
mode: LaunchMode.externalApplication,
);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange.shade700,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text(
'Download Update',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
),
],
),
),
);
},
);
}
@override
void dispose() {
try {
context.read<SplashProvider>().removeListener(_onStatusChanged);
} catch (_) {}
_fadeController.dispose();
_scaleController.dispose();
super.dispose();
@@ -108,4 +338,4 @@ class _SplashScreenState extends State<SplashScreen>
),
);
}
}
}