|
|
|
@ -2,6 +2,10 @@ import 'package:flutter/material.dart'; |
|
|
|
import 'package:http/http.dart' as http; |
|
|
|
import 'dart:convert'; |
|
|
|
|
|
|
|
import 'package:itrimobe/pages/tables.dart'; |
|
|
|
|
|
|
|
import '../layouts/main_layout.dart'; |
|
|
|
|
|
|
|
class CartPage extends StatefulWidget { |
|
|
|
final int tableId; |
|
|
|
final int personne; |
|
|
|
@ -119,8 +123,7 @@ class _CartPageState extends State<CartPage> { |
|
|
|
child: Text('Annuler', style: TextStyle(color: Colors.grey[600])), |
|
|
|
), |
|
|
|
ElevatedButton( |
|
|
|
onPressed: |
|
|
|
_isValidating |
|
|
|
onPressed: _isValidating |
|
|
|
? null |
|
|
|
: () { |
|
|
|
Navigator.of(context).pop(); |
|
|
|
@ -130,8 +133,7 @@ class _CartPageState extends State<CartPage> { |
|
|
|
backgroundColor: Colors.green[700], |
|
|
|
foregroundColor: Colors.white, |
|
|
|
), |
|
|
|
child: |
|
|
|
_isValidating |
|
|
|
child: _isValidating |
|
|
|
? SizedBox( |
|
|
|
width: 16, |
|
|
|
height: 16, |
|
|
|
@ -163,8 +165,7 @@ class _CartPageState extends State<CartPage> { |
|
|
|
"reservation_id": 1, // Peut être null si pas de réservation |
|
|
|
"serveur": "Serveur par défaut", // Valeur par défaut comme demandé |
|
|
|
"commentaires": _getOrderComments(), |
|
|
|
"items": |
|
|
|
_cartItems |
|
|
|
"items": _cartItems |
|
|
|
.map( |
|
|
|
(item) => { |
|
|
|
"menu_id": item.id, |
|
|
|
@ -206,8 +207,7 @@ class _CartPageState extends State<CartPage> { |
|
|
|
|
|
|
|
String _getOrderComments() { |
|
|
|
// Concaténer toutes les notes des articles pour les commentaires généraux |
|
|
|
List<String> allNotes = |
|
|
|
_cartItems |
|
|
|
List<String> allNotes = _cartItems |
|
|
|
.where((item) => item.notes.isNotEmpty) |
|
|
|
.map((item) => '${item.nom}: ${item.notes}') |
|
|
|
.toList(); |
|
|
|
@ -215,6 +215,7 @@ class _CartPageState extends State<CartPage> { |
|
|
|
return allNotes.join('; '); |
|
|
|
} |
|
|
|
|
|
|
|
// FONCTION CORRIGÉE POUR LA NAVIGATION VERS LES TABLES |
|
|
|
void _showSuccessDialog() { |
|
|
|
showDialog( |
|
|
|
context: context, |
|
|
|
@ -234,14 +235,13 @@ class _CartPageState extends State<CartPage> { |
|
|
|
actions: [ |
|
|
|
ElevatedButton( |
|
|
|
onPressed: () { |
|
|
|
Navigator.of(context).pop(); // Fermer le dialog |
|
|
|
Navigator.of(context).pop(); // Retourner au menu |
|
|
|
Navigator.of(context).pop(); // Retourner aux tables |
|
|
|
}, |
|
|
|
style: ElevatedButton.styleFrom( |
|
|
|
backgroundColor: Colors.green[700], |
|
|
|
foregroundColor: Colors.white, |
|
|
|
Navigator.of(context).pushAndRemoveUntil( |
|
|
|
MaterialPageRoute( |
|
|
|
builder: (context) => MainLayout(child: TablesScreen()), |
|
|
|
), |
|
|
|
(route) => false, |
|
|
|
); |
|
|
|
}, |
|
|
|
child: Text('OK'), |
|
|
|
), |
|
|
|
], |
|
|
|
@ -253,7 +253,8 @@ class _CartPageState extends State<CartPage> { |
|
|
|
Future<void> _updateTableStatus() async { |
|
|
|
try { |
|
|
|
final updateResponse = await http.put( |
|
|
|
Uri.parse('https://restaurant.careeracademy.mg/api/tables/${widget.tableId}'), |
|
|
|
Uri.parse( |
|
|
|
'https://restaurant.careeracademy.mg/api/tables/${widget.tableId}'), |
|
|
|
headers: {'Content-Type': 'application/json'}, |
|
|
|
body: json.encode({"status": "occupied"}), |
|
|
|
); |
|
|
|
@ -262,7 +263,6 @@ class _CartPageState extends State<CartPage> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void _showErrorDialog(String message) { |
|
|
|
showDialog( |
|
|
|
context: context, |
|
|
|
@ -317,8 +317,7 @@ class _CartPageState extends State<CartPage> { |
|
|
|
SizedBox(width: 16), |
|
|
|
], |
|
|
|
), |
|
|
|
body: |
|
|
|
_cartItems.isEmpty |
|
|
|
body: _cartItems.isEmpty |
|
|
|
? Center( |
|
|
|
child: Column( |
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
@ -354,8 +353,7 @@ class _CartPageState extends State<CartPage> { |
|
|
|
child: ListView.separated( |
|
|
|
padding: EdgeInsets.all(16), |
|
|
|
itemCount: _cartItems.length, |
|
|
|
separatorBuilder: |
|
|
|
(context, index) => SizedBox(height: 12), |
|
|
|
separatorBuilder: (context, index) => SizedBox(height: 12), |
|
|
|
itemBuilder: (context, index) { |
|
|
|
final item = _cartItems[index]; |
|
|
|
return Container( |
|
|
|
@ -375,8 +373,7 @@ class _CartPageState extends State<CartPage> { |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
Row( |
|
|
|
mainAxisAlignment: |
|
|
|
MainAxisAlignment.spaceBetween, |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
children: [ |
|
|
|
Expanded( |
|
|
|
child: Text( |
|
|
|
@ -418,15 +415,13 @@ class _CartPageState extends State<CartPage> { |
|
|
|
], |
|
|
|
SizedBox(height: 16), |
|
|
|
Row( |
|
|
|
mainAxisAlignment: |
|
|
|
MainAxisAlignment.spaceBetween, |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
children: [ |
|
|
|
// Contrôles de quantité |
|
|
|
Row( |
|
|
|
children: [ |
|
|
|
IconButton( |
|
|
|
onPressed: |
|
|
|
() => _updateQuantity( |
|
|
|
onPressed: () => _updateQuantity( |
|
|
|
index, |
|
|
|
item.quantity - 1, |
|
|
|
), |
|
|
|
@ -446,8 +441,7 @@ class _CartPageState extends State<CartPage> { |
|
|
|
), |
|
|
|
SizedBox(width: 16), |
|
|
|
IconButton( |
|
|
|
onPressed: |
|
|
|
() => _updateQuantity( |
|
|
|
onPressed: () => _updateQuantity( |
|
|
|
index, |
|
|
|
item.quantity + 1, |
|
|
|
), |
|
|
|
@ -553,8 +547,7 @@ class _CartPageState extends State<CartPage> { |
|
|
|
SizedBox( |
|
|
|
width: double.infinity, |
|
|
|
child: ElevatedButton( |
|
|
|
onPressed: |
|
|
|
_cartItems.isNotEmpty && !_isValidating |
|
|
|
onPressed: _cartItems.isNotEmpty && !_isValidating |
|
|
|
? _showConfirmationDialog |
|
|
|
: null, |
|
|
|
style: ElevatedButton.styleFrom( |
|
|
|
|