diff --git a/lib/pages/caisse_screen.dart b/lib/pages/caisse_screen.dart index 84ee4db..d5eebfb 100644 --- a/lib/pages/caisse_screen.dart +++ b/lib/pages/caisse_screen.dart @@ -111,8 +111,8 @@ class _CaisseScreenState extends State { return; } - // 🔄 Redirige vers la facture - Navigator.of(context).pushReplacement( + // 🔄 Redirige vers la facture et attend le retour + final result = await Navigator.of(context).push( MaterialPageRoute( builder: (context) => FactureScreen( commande: commande!, @@ -121,6 +121,11 @@ class _CaisseScreenState extends State { ), ), ); + + // Quand on revient de la facture, on retourne à la page précédente avec succès + if (mounted) { + Navigator.of(context).pop(true); + } } else { _showErrorDialog('Le paiement a échoué. Veuillez réessayer.'); } diff --git a/lib/pages/commande_item_validation.dart b/lib/pages/commande_item_validation.dart index 9752200..bc932f2 100644 --- a/lib/pages/commande_item_validation.dart +++ b/lib/pages/commande_item_validation.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; import 'package:intl/intl.dart'; +import '../layouts/main_layout.dart'; import '../services/pdf_impression_commande.dart'; import 'commandes_screen.dart'; @@ -423,12 +424,16 @@ class _ValidateAddItemsPageState extends State { // Méthode pour naviguer avec succès void _navigateBackWithSuccess() { // Fermer toutes les pages précédentes et rediriger vers OrdersManagementScreen - Navigator.of(context).pushAndRemoveUntil( - MaterialPageRoute( - builder: (context) => OrdersManagementScreen(), + Navigator.of(context).pushAndRemoveUntil( + MaterialPageRoute( + builder: (context) => MainLayout( + currentRoute: '/commandes', // ou '/tables' selon ton besoin + child: OrdersManagementScreen(), ), - (Route route) => false, // Supprime toutes les pages précédentes - ); + ), + (Route route) => false, +); + // Optionnel : petit délai pour laisser le temps à la navigation Future.delayed(Duration(milliseconds: 300), () { diff --git a/lib/pages/facture_screen.dart b/lib/pages/facture_screen.dart index fcc428e..8ee1d60 100644 --- a/lib/pages/facture_screen.dart +++ b/lib/pages/facture_screen.dart @@ -58,7 +58,11 @@ class _FactureScreenState extends State { elevation: 0, leading: IconButton( icon: const Icon(Icons.arrow_back, color: Colors.black), - onPressed: () => Navigator.of(context).pop(), + onPressed: () { + // Retourner 2 fois en arrière (facture -> caisse -> liste commandes) + Navigator.of(context).pop(); + Navigator.of(context).pop(true); // true pour indiquer le succès + }, ), title: const Text( 'Retour', diff --git a/lib/widgets/command_card.dart b/lib/widgets/command_card.dart index 409b706..561fa53 100644 --- a/lib/widgets/command_card.dart +++ b/lib/widgets/command_card.dart @@ -4,12 +4,14 @@ import 'package:itrimobe/models/tables_order.dart'; class CommandeCard extends StatelessWidget { final TableOrder commande; - final VoidCallback onAllerCaisse; + final Future Function() onAllerCaisse; // Changé en Future Function() + final VoidCallback? onRefresh; const CommandeCard({ super.key, required this.commande, required this.onAllerCaisse, + this.onRefresh, }); String _formatTime(DateTime dateTime) { @@ -18,7 +20,6 @@ class CommandeCard extends StatelessWidget { @override Widget build(BuildContext context) { - return Container( margin: EdgeInsets.only(bottom: 16), decoration: BoxDecoration( @@ -38,7 +39,6 @@ class CommandeCard extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - // Header avec numéro de table et badge Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -62,7 +62,7 @@ class CommandeCard extends StatelessWidget { Icon(Icons.check_circle, color: Colors.white, size: 16), SizedBox(width: 4), Text( - 'Près à encaisser', + 'Prêt à encaisser', style: TextStyle( color: Colors.white, fontSize: 12, @@ -77,13 +77,11 @@ class CommandeCard extends StatelessWidget { SizedBox(height: 12), - // Informations détaillées Row( children: [ Icon(Icons.access_time, size: 16, color: Colors.grey[600]), SizedBox(width: 6), Text( - // Fixed: Pass DateTime directly, not as string commande.date != null ? _formatTime(commande.date!) : 'Date non disponible', style: TextStyle(color: Colors.grey[600], fontSize: 14), ), @@ -92,10 +90,8 @@ class CommandeCard extends StatelessWidget { SizedBox(height: 16), - // Total et bouton Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, - // alignItems: MainAxisAlignment.center, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -115,7 +111,15 @@ class CommandeCard extends StatelessWidget { ], ), ElevatedButton.icon( - onPressed: onAllerCaisse, + onPressed: () async { + // Attendre que la navigation soit terminée + await onAllerCaisse(); + + // Rafraîchir la page + if (onRefresh != null) { + onRefresh!(); + } + }, icon: Icon(Icons.point_of_sale, size: 18), label: Text('Aller à la caisse'), style: ElevatedButton.styleFrom(