feat: popup de fin de session aux couleurs de l'appli avec export IA integre
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
@@ -701,77 +701,93 @@ class _AnalysisScreenContentState extends State<_AnalysisScreenContent> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showSaveSessionDialog(BuildContext context, AnalysisProvider provider) {
|
Future<void> _showSaveSessionDialog(
|
||||||
|
BuildContext context,
|
||||||
|
AnalysisProvider provider,
|
||||||
|
) async {
|
||||||
|
// L'option « Participer à l'entraînement IA » (Paramètres) est lue AVANT
|
||||||
|
// d'ouvrir la popup : elle décide de la présence du bouton d'export.
|
||||||
|
final canExport =
|
||||||
|
await WalletIdentityService().isUploadEnabled() &&
|
||||||
|
provider.state == AnalysisState.success;
|
||||||
|
|
||||||
|
if (!context.mounted) return;
|
||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: const Text('Session Terminee'),
|
// Protège des petits écrans / grandes polices : la popup défile au
|
||||||
content: Column(
|
// lieu de déborder.
|
||||||
mainAxisSize: MainAxisSize.min,
|
scrollable: true,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
// En-tête bleu pleine largeur : le titre occupe toute la bande, d'où
|
||||||
|
// les paddings mis à zéro.
|
||||||
|
titlePadding: EdgeInsets.zero,
|
||||||
|
contentPadding: const EdgeInsets.fromLTRB(20, 16, 20, 16),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
),
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
title: Container(
|
||||||
|
width: double.infinity,
|
||||||
|
color: AppTheme.primaryColor,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||||
|
child: const Row(
|
||||||
children: [
|
children: [
|
||||||
Text('Nombre de tirs: ${provider.shotCount}'),
|
Icon(Icons.flag, color: Colors.white),
|
||||||
Text('Score total: ${provider.totalScore}'),
|
SizedBox(width: 10),
|
||||||
const SizedBox(height: 16),
|
Text(
|
||||||
const Text('Voulez-vous enregistrer cette session ?'),
|
'Session terminée',
|
||||||
// Export vers le backend IA : proposé ici (et non plus dans
|
style: TextStyle(
|
||||||
// l'AppBar). Visible seulement si l'option est activée dans les
|
color: Colors.white,
|
||||||
// Paramètres ET si l'analyse a réussi.
|
fontSize: 18,
|
||||||
FutureBuilder<bool>(
|
fontWeight: FontWeight.bold,
|
||||||
future: WalletIdentityService().isUploadEnabled(),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
final isEnabled = snapshot.data ?? false;
|
|
||||||
if (!isEnabled ||
|
|
||||||
provider.state != AnalysisState.success) {
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 12),
|
|
||||||
child: OutlinedButton.icon(
|
|
||||||
icon: const Icon(Icons.cloud_upload),
|
|
||||||
label: const Text('Exporter pour IA'),
|
|
||||||
onPressed: () async {
|
|
||||||
if (provider.state != AnalysisState.success) return;
|
|
||||||
|
|
||||||
// On capture messenger et session AVANT l'await pour
|
|
||||||
// éviter tout usage de context après un gap async.
|
|
||||||
final messenger = ScaffoldMessenger.of(context);
|
|
||||||
final sp = context.read<SessionProvider>();
|
|
||||||
|
|
||||||
messenger.showSnackBar(
|
|
||||||
const SnackBar(
|
|
||||||
content: Text('Exportation en cours...'),
|
|
||||||
),
|
),
|
||||||
);
|
|
||||||
|
|
||||||
final success = await provider.exportToAiBackend(
|
|
||||||
sessionId: sp.activeSessionId,
|
|
||||||
distance: sp.distance,
|
|
||||||
weapon: sp.currentWeapon,
|
|
||||||
);
|
|
||||||
|
|
||||||
messenger.hideCurrentSnackBar();
|
|
||||||
messenger.showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(
|
|
||||||
success
|
|
||||||
? 'Export réussi vers le backend IA !'
|
|
||||||
: (provider.errorMessage ??
|
|
||||||
'Erreur d\'export'),
|
|
||||||
),
|
|
||||||
backgroundColor: success
|
|
||||||
? AppTheme.successColor
|
|
||||||
: AppTheme.errorColor,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
actions: [
|
),
|
||||||
|
// Les boutons sont dans le contenu (et non dans `actions`) pour être
|
||||||
|
// tous à la même largeur, alignés les uns sous les autres.
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
_buildDialogRecap(context, provider),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
const Text('Voulez-vous enregistrer cette session ?'),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
_buildDialogButton(
|
||||||
|
icon: const Icon(Icons.add_a_photo, color: Colors.white),
|
||||||
|
label: 'AJOUTER UNE CIBLE',
|
||||||
|
color: AppTheme.secondaryColor,
|
||||||
|
onPressed: () => _saveAndAddTarget(context, provider),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
_buildDialogButton(
|
||||||
|
icon: const Icon(Icons.save, color: Colors.white),
|
||||||
|
label: 'TERMINER TOUT',
|
||||||
|
color: AppTheme.primaryColor,
|
||||||
|
onPressed: () => _finishSession(context, provider),
|
||||||
|
),
|
||||||
|
// Bouton d'export : uniquement si l'entraînement IA est autorisé.
|
||||||
|
if (canExport) ...[
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
_buildDialogButton(
|
||||||
|
icon: Image.asset(
|
||||||
|
'assets/icons/cloud_save.png',
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
// L'icône est un trait noir : on la recolore en blanc pour
|
||||||
|
// qu'elle ressorte sur le bouton.
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
label: 'TERMINER TOUT ET EXPORTER',
|
||||||
|
color: AppTheme.warningColor,
|
||||||
|
onPressed: () =>
|
||||||
|
_finishSession(context, provider, export: true),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
const SizedBox(height: 4),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
@@ -793,8 +809,72 @@ class _AnalysisScreenContentState extends State<_AnalysisScreenContent> {
|
|||||||
},
|
},
|
||||||
child: const Text('ANNULER'),
|
child: const Text('ANNULER'),
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
],
|
||||||
onPressed: () async {
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Rappel chiffré (tirs / score) en tête de la popup de fin de session.
|
||||||
|
Widget _buildDialogRecap(BuildContext context, AnalysisProvider provider) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: AppTheme.primaryColor.withValues(alpha: 0.10),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
|
children: [
|
||||||
|
_buildRecapValue(context, '${provider.shotCount}', 'Tirs'),
|
||||||
|
_buildRecapValue(context, '${provider.totalScore}', 'Score total'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildRecapValue(BuildContext context, String value, String label) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
value,
|
||||||
|
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: AppTheme.primaryColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(label, style: Theme.of(context).textTheme.bodySmall),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Bouton pleine largeur de la popup, aux couleurs du thème.
|
||||||
|
Widget _buildDialogButton({
|
||||||
|
required Widget icon,
|
||||||
|
required String label,
|
||||||
|
required Color color,
|
||||||
|
required VoidCallback onPressed,
|
||||||
|
}) {
|
||||||
|
return ElevatedButton.icon(
|
||||||
|
icon: icon,
|
||||||
|
label: Text(label, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: color,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onPressed: onPressed,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enregistre la cible courante et enchaîne sur une nouvelle capture.
|
||||||
|
Future<void> _saveAndAddTarget(
|
||||||
|
BuildContext context,
|
||||||
|
AnalysisProvider provider,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
final sessionProvider = context.read<SessionProvider>();
|
final sessionProvider = context.read<SessionProvider>();
|
||||||
final analysis = await provider.saveSession(
|
final analysis = await provider.saveSession(
|
||||||
@@ -811,9 +891,7 @@ class _AnalysisScreenContentState extends State<_AnalysisScreenContent> {
|
|||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
Navigator.pushAndRemoveUntil(
|
Navigator.pushAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => const CaptureScreen()),
|
||||||
builder: (context) => const CaptureScreen(),
|
|
||||||
),
|
|
||||||
(route) => route.isFirst,
|
(route) => route.isFirst,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -827,13 +905,24 @@ class _AnalysisScreenContentState extends State<_AnalysisScreenContent> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
child: const Text('AJOUTER UNE CIBLE'),
|
|
||||||
),
|
/// Clôture la session et revient sur l'onglet Statistiques.
|
||||||
ElevatedButton(
|
///
|
||||||
onPressed: () async {
|
/// Avec [export], la cible est en plus envoyée au backend d'entraînement IA.
|
||||||
try {
|
/// L'enregistrement local reste prioritaire : un échec d'export n'empêche
|
||||||
|
/// jamais la session d'être sauvegardée.
|
||||||
|
Future<void> _finishSession(
|
||||||
|
BuildContext context,
|
||||||
|
AnalysisProvider provider, {
|
||||||
|
bool export = false,
|
||||||
|
}) async {
|
||||||
|
// Messenger et session capturés AVANT les await : le contexte de la popup
|
||||||
|
// ne sera plus valide ensuite.
|
||||||
|
final messenger = ScaffoldMessenger.of(context);
|
||||||
final sessionProvider = context.read<SessionProvider>();
|
final sessionProvider = context.read<SessionProvider>();
|
||||||
|
|
||||||
|
try {
|
||||||
await provider.saveSession(
|
await provider.saveSession(
|
||||||
sessionId: sessionProvider.activeSessionId,
|
sessionId: sessionProvider.activeSessionId,
|
||||||
weaponName: sessionProvider.currentWeapon,
|
weaponName: sessionProvider.currentWeapon,
|
||||||
@@ -842,6 +931,19 @@ class _AnalysisScreenContentState extends State<_AnalysisScreenContent> {
|
|||||||
date: sessionProvider.sessionDate,
|
date: sessionProvider.sessionDate,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
bool? exportSucceeded;
|
||||||
|
if (export) {
|
||||||
|
messenger.showSnackBar(
|
||||||
|
const SnackBar(content: Text('Exportation en cours...')),
|
||||||
|
);
|
||||||
|
exportSucceeded = await provider.exportToAiBackend(
|
||||||
|
sessionId: sessionProvider.activeSessionId,
|
||||||
|
distance: sessionProvider.distance,
|
||||||
|
weapon: sessionProvider.currentWeapon,
|
||||||
|
);
|
||||||
|
messenger.hideCurrentSnackBar();
|
||||||
|
}
|
||||||
|
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
sessionProvider.endSession();
|
sessionProvider.endSession();
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
@@ -849,9 +951,23 @@ class _AnalysisScreenContentState extends State<_AnalysisScreenContent> {
|
|||||||
// Fin de session : on atterrit sur les statistiques.
|
// Fin de session : on atterrit sur les statistiques.
|
||||||
openMainTab(mainTabStats);
|
openMainTab(mainTabStats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exportSucceeded != null) {
|
||||||
|
messenger.showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
exportSucceeded
|
||||||
|
? 'Export réussi vers le backend IA !'
|
||||||
|
: (provider.errorMessage ?? 'Erreur d\'export'),
|
||||||
|
),
|
||||||
|
backgroundColor: exportSucceeded
|
||||||
|
? AppTheme.successColor
|
||||||
|
: AppTheme.errorColor,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (context.mounted) {
|
messenger.showSnackBar(
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text('Erreur: $e'),
|
content: Text('Erreur: $e'),
|
||||||
backgroundColor: AppTheme.errorColor,
|
backgroundColor: AppTheme.errorColor,
|
||||||
@@ -859,11 +975,4 @@ class _AnalysisScreenContentState extends State<_AnalysisScreenContent> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
child: const Text('TERMINER TOUT'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+2
-4
@@ -93,10 +93,8 @@ flutter:
|
|||||||
# the material Icons class.
|
# the material Icons class.
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
|
||||||
# To add assets to your application, add an assets section, like this:
|
assets:
|
||||||
# assets:
|
- assets/icons/
|
||||||
# - images/a_dot_burr.jpeg
|
|
||||||
# - images/a_dot_ham.jpeg
|
|
||||||
|
|
||||||
# An image asset can refer to one or more resolution-specific "variants", see
|
# An image asset can refer to one or more resolution-specific "variants", see
|
||||||
# https://flutter.dev/to/resolution-aware-images
|
# https://flutter.dev/to/resolution-aware-images
|
||||||
|
|||||||
Reference in New Issue
Block a user