fix: Amélioration de l'expérience utilisateur lors de la génération de QR codes
Cette mise à jour améliore la génération de QR codes pour les équipements et les containers en ajoutant un retour visuel à l'utilisateur et une gestion des erreurs plus robuste. **Changements :** - **Ajout d'un indicateur de chargement :** Un `CircularProgressIndicator` est désormais affiché pendant que les données des équipements ou des containers sélectionnés sont récupérées, informant l'utilisateur qu'une opération est en cours. - **Gestion des erreurs :** Un bloc `try...catch` a été ajouté autour de la logique de génération dans les pages de gestion des équipements (`EquipmentManagementPage`) et des containers (`ContainerManagementPage`). - **Affichage des erreurs :** En cas d'échec, le chargement est stoppé et une `SnackBar` rouge apparaît pour notifier l'utilisateur de l'erreur, améliorant ainsi la robustesse de la fonctionnalité.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
/// Configuration de la version de l'application
|
||||
class AppVersion {
|
||||
static const String version = '0.3.8';
|
||||
static const String version = '1.0.3';
|
||||
|
||||
/// Retourne la version complète de l'application
|
||||
static String get fullVersion => 'v$version';
|
||||
|
||||
|
||||
/// Retourne la version avec un préfixe personnalisé
|
||||
static String getVersionWithPrefix(String prefix) => '$prefix $version';
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import 'views/reset_password_page.dart';
|
||||
import 'config/env.dart';
|
||||
import 'config/api_config.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'views/widgets/common/update_dialog.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -96,9 +97,10 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'EM2 ERP',
|
||||
theme: ThemeData(
|
||||
return UpdateChecker(
|
||||
child: MaterialApp(
|
||||
title: 'EM2 ERP',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.red,
|
||||
primaryColor: AppColors.noir,
|
||||
colorScheme:
|
||||
@@ -181,6 +183,7 @@ class MyApp extends StatelessWidget {
|
||||
);
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
117
em2rp/lib/services/update_service.dart
Normal file
117
em2rp/lib/services/update_service.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
import 'package:em2rp/config/app_version.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
/// Service pour gérer les mises à jour de l'application
|
||||
class UpdateService {
|
||||
// URL de votre version.json déployé sur Firebase Hosting
|
||||
static const String versionUrl = 'https://app.em2events.fr/version.json';
|
||||
|
||||
/// Vérifie si une mise à jour est disponible
|
||||
static Future<UpdateInfo?> checkForUpdate() async {
|
||||
try {
|
||||
// Récupérer la version actuelle depuis AppVersion
|
||||
final currentVersion = AppVersion.version;
|
||||
|
||||
if (kDebugMode) {
|
||||
print('[UpdateService] Current version: $currentVersion');
|
||||
}
|
||||
|
||||
// Récupérer la version depuis le serveur (avec cache-busting)
|
||||
final timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||
final response = await http.get(
|
||||
Uri.parse('$versionUrl?t=$timestamp'),
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
||||
'Pragma': 'no-cache',
|
||||
'Expires': '0',
|
||||
},
|
||||
).timeout(const Duration(seconds: 10));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = json.decode(response.body);
|
||||
final serverVersion = data['version'] as String;
|
||||
|
||||
if (kDebugMode) {
|
||||
print('[UpdateService] Server version: $serverVersion');
|
||||
}
|
||||
|
||||
// Comparer les versions
|
||||
if (_isNewerVersion(serverVersion, currentVersion)) {
|
||||
return UpdateInfo(
|
||||
currentVersion: currentVersion,
|
||||
newVersion: serverVersion,
|
||||
updateUrl: data['updateUrl'] as String?,
|
||||
releaseNotes: data['releaseNotes'] as String?,
|
||||
forceUpdate: data['forceUpdate'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('[UpdateService] Error checking for update: $e');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Compare deux versions sémantiques (x.y.z)
|
||||
/// Retourne true si newVersion > currentVersion
|
||||
static bool _isNewerVersion(String newVersion, String currentVersion) {
|
||||
final newParts = newVersion.split('.').map(int.parse).toList();
|
||||
final currentParts = currentVersion.split('.').map(int.parse).toList();
|
||||
|
||||
// Comparer major
|
||||
if (newParts[0] > currentParts[0]) return true;
|
||||
if (newParts[0] < currentParts[0]) return false;
|
||||
|
||||
// Comparer minor
|
||||
if (newParts[1] > currentParts[1]) return true;
|
||||
if (newParts[1] < currentParts[1]) return false;
|
||||
|
||||
// Comparer patch
|
||||
return newParts[2] > currentParts[2];
|
||||
}
|
||||
|
||||
/// Force le rechargement de l'application (vide le cache)
|
||||
static Future<void> reloadApp() async {
|
||||
if (kIsWeb) {
|
||||
// Pour le web, recharger la page en utilisant JavaScript
|
||||
final url = Uri.base;
|
||||
await launchUrl(url, webOnlyWindowName: '_self');
|
||||
}
|
||||
}
|
||||
|
||||
/// Vérification automatique au démarrage
|
||||
static Future<UpdateInfo?> checkOnStartup() async {
|
||||
// Attendre un peu avant de vérifier (pour ne pas ralentir le démarrage)
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
return await checkForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/// Informations sur une mise à jour disponible
|
||||
class UpdateInfo {
|
||||
final String currentVersion;
|
||||
final String newVersion;
|
||||
final String? updateUrl;
|
||||
final String? releaseNotes;
|
||||
final bool forceUpdate;
|
||||
|
||||
UpdateInfo({
|
||||
required this.currentVersion,
|
||||
required this.newVersion,
|
||||
this.updateUrl,
|
||||
this.releaseNotes,
|
||||
this.forceUpdate = false,
|
||||
});
|
||||
|
||||
String get versionDifference {
|
||||
return 'Nouvelle version disponible';
|
||||
}
|
||||
}
|
||||
|
||||
223
em2rp/lib/views/widgets/common/update_dialog.dart
Normal file
223
em2rp/lib/views/widgets/common/update_dialog.dart
Normal file
@@ -0,0 +1,223 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:em2rp/services/update_service.dart';
|
||||
import 'package:em2rp/utils/colors.dart';
|
||||
|
||||
/// Dialog pour informer l'utilisateur d'une mise à jour disponible
|
||||
class UpdateDialog extends StatelessWidget {
|
||||
final UpdateInfo updateInfo;
|
||||
|
||||
const UpdateDialog({
|
||||
super.key,
|
||||
required this.updateInfo,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
// Empêcher la fermeture si c'est une mise à jour forcée
|
||||
canPop: !updateInfo.forceUpdate,
|
||||
child: AlertDialog(
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(
|
||||
updateInfo.forceUpdate ? Icons.update : Icons.system_update,
|
||||
color: updateInfo.forceUpdate ? Colors.orange : AppColors.rouge,
|
||||
size: 28,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
updateInfo.forceUpdate
|
||||
? 'Mise à jour requise'
|
||||
: 'Mise à jour disponible',
|
||||
style: const TextStyle(fontSize: 20),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Versions
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Version actuelle :',
|
||||
style: TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
Text(
|
||||
updateInfo.currentVersion,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Nouvelle version :',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text(
|
||||
updateInfo.newVersion,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.rouge,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Message principal
|
||||
if (updateInfo.forceUpdate) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.orange, width: 2),
|
||||
),
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.warning, color: Colors.orange),
|
||||
SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Cette mise à jour est obligatoire pour continuer à utiliser l\'application.',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.orange,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
Text(
|
||||
updateInfo.forceUpdate
|
||||
? 'L\'application va se recharger pour appliquer la mise à jour.'
|
||||
: 'Une nouvelle version de l\'application est disponible. Voulez-vous mettre à jour maintenant ?',
|
||||
style: const TextStyle(fontSize: 15),
|
||||
),
|
||||
|
||||
// Notes de version
|
||||
if (updateInfo.releaseNotes != null &&
|
||||
updateInfo.releaseNotes!.isNotEmpty) ...[
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'Nouveautés :',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue.withValues(alpha: 0.05),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.blue.withValues(alpha: 0.2)),
|
||||
),
|
||||
child: Text(
|
||||
updateInfo.releaseNotes!,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
if (!updateInfo.forceUpdate)
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Plus tard'),
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
// Recharger l'application
|
||||
await UpdateService.reloadApp();
|
||||
},
|
||||
icon: const Icon(Icons.refresh, color: Colors.white),
|
||||
label: Text(
|
||||
updateInfo.forceUpdate ? 'Mettre à jour' : 'Mettre à jour maintenant',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: updateInfo.forceUpdate ? Colors.orange : AppColors.rouge,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Widget pour vérifier automatiquement les mises à jour
|
||||
class UpdateChecker extends StatefulWidget {
|
||||
final Widget child;
|
||||
|
||||
const UpdateChecker({
|
||||
super.key,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
@override
|
||||
State<UpdateChecker> createState() => _UpdateCheckerState();
|
||||
}
|
||||
|
||||
class _UpdateCheckerState extends State<UpdateChecker> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkForUpdate();
|
||||
}
|
||||
|
||||
Future<void> _checkForUpdate() async {
|
||||
final updateInfo = await UpdateService.checkOnStartup();
|
||||
|
||||
if (updateInfo != null && mounted) {
|
||||
// Attendre que l'interface soit complètement chargée
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: !updateInfo.forceUpdate,
|
||||
builder: (context) => UpdateDialog(updateInfo: updateInfo),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return widget.child;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user