Browse Source

reectification

master
andrymodeste 1 month ago
parent
commit
7d2c6f5965
  1. 9
      lib/pages/caisse_screen.dart
  2. 9
      lib/pages/commande_item_validation.dart
  3. 6
      lib/pages/facture_screen.dart
  4. 22
      lib/widgets/command_card.dart

9
lib/pages/caisse_screen.dart

@ -111,8 +111,8 @@ class _CaisseScreenState extends State<CaisseScreen> {
return; return;
} }
// 🔄 Redirige vers la facture // 🔄 Redirige vers la facture et attend le retour
Navigator.of(context).pushReplacement( final result = await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => FactureScreen( builder: (context) => FactureScreen(
commande: commande!, commande: commande!,
@ -121,6 +121,11 @@ class _CaisseScreenState extends State<CaisseScreen> {
), ),
), ),
); );
// Quand on revient de la facture, on retourne à la page précédente avec succès
if (mounted) {
Navigator.of(context).pop(true);
}
} else { } else {
_showErrorDialog('Le paiement a échoué. Veuillez réessayer.'); _showErrorDialog('Le paiement a échoué. Veuillez réessayer.');
} }

9
lib/pages/commande_item_validation.dart

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'dart:convert'; import 'dart:convert';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import '../layouts/main_layout.dart';
import '../services/pdf_impression_commande.dart'; import '../services/pdf_impression_commande.dart';
import 'commandes_screen.dart'; import 'commandes_screen.dart';
@ -425,11 +426,15 @@ void _navigateBackWithSuccess() {
// Fermer toutes les pages précédentes et rediriger vers OrdersManagementScreen // Fermer toutes les pages précédentes et rediriger vers OrdersManagementScreen
Navigator.of(context).pushAndRemoveUntil( Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => OrdersManagementScreen(), builder: (context) => MainLayout(
currentRoute: '/commandes', // ou '/tables' selon ton besoin
child: OrdersManagementScreen(),
), ),
(Route<dynamic> route) => false, // Supprime toutes les pages précédentes ),
(Route<dynamic> route) => false,
); );
// Optionnel : petit délai pour laisser le temps à la navigation // Optionnel : petit délai pour laisser le temps à la navigation
Future.delayed(Duration(milliseconds: 300), () { Future.delayed(Duration(milliseconds: 300), () {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(

6
lib/pages/facture_screen.dart

@ -58,7 +58,11 @@ class _FactureScreenState extends State<FactureScreen> {
elevation: 0, elevation: 0,
leading: IconButton( leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.black), 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( title: const Text(
'Retour', 'Retour',

22
lib/widgets/command_card.dart

@ -4,12 +4,14 @@ import 'package:itrimobe/models/tables_order.dart';
class CommandeCard extends StatelessWidget { class CommandeCard extends StatelessWidget {
final TableOrder commande; final TableOrder commande;
final VoidCallback onAllerCaisse; final Future<void> Function() onAllerCaisse; // Changé en Future<void> Function()
final VoidCallback? onRefresh;
const CommandeCard({ const CommandeCard({
super.key, super.key,
required this.commande, required this.commande,
required this.onAllerCaisse, required this.onAllerCaisse,
this.onRefresh,
}); });
String _formatTime(DateTime dateTime) { String _formatTime(DateTime dateTime) {
@ -18,7 +20,6 @@ class CommandeCard extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
margin: EdgeInsets.only(bottom: 16), margin: EdgeInsets.only(bottom: 16),
decoration: BoxDecoration( decoration: BoxDecoration(
@ -38,7 +39,6 @@ class CommandeCard extends StatelessWidget {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Header avec numéro de table et badge
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -62,7 +62,7 @@ class CommandeCard extends StatelessWidget {
Icon(Icons.check_circle, color: Colors.white, size: 16), Icon(Icons.check_circle, color: Colors.white, size: 16),
SizedBox(width: 4), SizedBox(width: 4),
Text( Text(
'Près à encaisser', 'Prêt à encaisser',
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 12, fontSize: 12,
@ -77,13 +77,11 @@ class CommandeCard extends StatelessWidget {
SizedBox(height: 12), SizedBox(height: 12),
// Informations détaillées
Row( Row(
children: [ children: [
Icon(Icons.access_time, size: 16, color: Colors.grey[600]), Icon(Icons.access_time, size: 16, color: Colors.grey[600]),
SizedBox(width: 6), SizedBox(width: 6),
Text( Text(
// Fixed: Pass DateTime directly, not as string
commande.date != null ? _formatTime(commande.date!) : 'Date non disponible', commande.date != null ? _formatTime(commande.date!) : 'Date non disponible',
style: TextStyle(color: Colors.grey[600], fontSize: 14), style: TextStyle(color: Colors.grey[600], fontSize: 14),
), ),
@ -92,10 +90,8 @@ class CommandeCard extends StatelessWidget {
SizedBox(height: 16), SizedBox(height: 16),
// Total et bouton
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
// alignItems: MainAxisAlignment.center,
children: [ children: [
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -115,7 +111,15 @@ class CommandeCard extends StatelessWidget {
], ],
), ),
ElevatedButton.icon( 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), icon: Icon(Icons.point_of_sale, size: 18),
label: Text('Aller à la caisse'), label: Text('Aller à la caisse'),
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(

Loading…
Cancel
Save