|
|
@ -1,3 +1,4 @@ |
|
|
|
|
|
import 'package:flutter/foundation.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
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'; |
|
|
@ -9,8 +10,7 @@ class MenuPage extends StatefulWidget { |
|
|
final int tableId; |
|
|
final int tableId; |
|
|
final int personne; |
|
|
final int personne; |
|
|
|
|
|
|
|
|
const MenuPage({Key? key, required this.tableId, required this.personne}) |
|
|
const MenuPage({super.key, required this.tableId, required this.personne}); |
|
|
: super(key: key); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
|
State<MenuPage> createState() => _MenuPageState(); |
|
|
State<MenuPage> createState() => _MenuPageState(); |
|
|
@ -20,7 +20,7 @@ class _MenuPageState extends State<MenuPage> { |
|
|
int? _selectedCategory; |
|
|
int? _selectedCategory; |
|
|
List<dynamic> _categories = []; |
|
|
List<dynamic> _categories = []; |
|
|
List<dynamic> _menus = []; |
|
|
List<dynamic> _menus = []; |
|
|
List<dynamic> _cart = []; |
|
|
final List<dynamic> _cart = []; |
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
|
void initState() { |
|
|
void initState() { |
|
|
@ -49,12 +49,16 @@ class _MenuPageState extends State<MenuPage> { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
if (kDebugMode) { |
|
|
print("Erreur API catégories: ${response.statusCode}"); |
|
|
print("Erreur API catégories: ${response.statusCode}"); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
|
|
|
if (kDebugMode) { |
|
|
print("Exception fetchCategories: $e"); |
|
|
print("Exception fetchCategories: $e"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Future<void> fetchMenus(int categoryId) async { |
|
|
Future<void> fetchMenus(int categoryId) async { |
|
|
try { |
|
|
try { |
|
|
@ -73,12 +77,16 @@ class _MenuPageState extends State<MenuPage> { |
|
|
_menus = menusList; |
|
|
_menus = menusList; |
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
if (kDebugMode) { |
|
|
print("Erreur API menus: ${response.statusCode}"); |
|
|
print("Erreur API menus: ${response.statusCode}"); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
|
|
|
if (kDebugMode) { |
|
|
print("Exception fetchMenus: $e"); |
|
|
print("Exception fetchMenus: $e"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void changeCategory(int id) { |
|
|
void changeCategory(int id) { |
|
|
setState(() { |
|
|
setState(() { |
|
|
@ -145,13 +153,13 @@ class _MenuPageState extends State<MenuPage> { |
|
|
Widget build(BuildContext context) { |
|
|
Widget build(BuildContext context) { |
|
|
return Scaffold( |
|
|
return Scaffold( |
|
|
appBar: AppBar( |
|
|
appBar: AppBar( |
|
|
title: Text("Menu"), |
|
|
title: const Text("Menu"), |
|
|
actions: [ |
|
|
actions: [ |
|
|
IconButton( |
|
|
IconButton( |
|
|
onPressed: () { |
|
|
onPressed: () { |
|
|
if (_selectedCategory != null) fetchMenus(_selectedCategory!); |
|
|
if (_selectedCategory != null) fetchMenus(_selectedCategory!); |
|
|
}, |
|
|
}, |
|
|
icon: Icon(Icons.refresh), |
|
|
icon: const Icon(Icons.refresh), |
|
|
), |
|
|
), |
|
|
], |
|
|
], |
|
|
), |
|
|
), |
|
|
@ -162,7 +170,7 @@ class _MenuPageState extends State<MenuPage> { |
|
|
padding: const EdgeInsets.all(8.0), |
|
|
padding: const EdgeInsets.all(8.0), |
|
|
child: Text( |
|
|
child: Text( |
|
|
"Table ${widget.tableId} • ${widget.personne} personne${widget.personne > 1 ? 's' : ''}", |
|
|
"Table ${widget.tableId} • ${widget.personne} personne${widget.personne > 1 ? 's' : ''}", |
|
|
style: TextStyle(fontSize: 16), |
|
|
style: const TextStyle(fontSize: 16), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
if (_categories.isNotEmpty) |
|
|
if (_categories.isNotEmpty) |
|
|
@ -174,7 +182,7 @@ class _MenuPageState extends State<MenuPage> { |
|
|
}).toList(), |
|
|
}).toList(), |
|
|
) |
|
|
) |
|
|
else |
|
|
else |
|
|
Center(child: CircularProgressIndicator()), |
|
|
const Center(child: CircularProgressIndicator()), |
|
|
Expanded( |
|
|
Expanded( |
|
|
child: |
|
|
child: |
|
|
_menus.isNotEmpty |
|
|
_menus.isNotEmpty |
|
|
@ -183,7 +191,7 @@ class _MenuPageState extends State<MenuPage> { |
|
|
itemBuilder: (context, index) { |
|
|
itemBuilder: (context, index) { |
|
|
final item = _menus[index]; |
|
|
final item = _menus[index]; |
|
|
return Card( |
|
|
return Card( |
|
|
margin: EdgeInsets.all(8), |
|
|
margin: const EdgeInsets.all(8), |
|
|
child: ListTile( |
|
|
child: ListTile( |
|
|
onTap: |
|
|
onTap: |
|
|
() => showAddToCartModal( |
|
|
() => showAddToCartModal( |
|
|
@ -204,7 +212,9 @@ class _MenuPageState extends State<MenuPage> { |
|
|
), |
|
|
), |
|
|
title: Text( |
|
|
title: Text( |
|
|
item['nom'] ?? 'Nom non disponible', |
|
|
item['nom'] ?? 'Nom non disponible', |
|
|
style: TextStyle(fontWeight: FontWeight.bold), |
|
|
style: const TextStyle( |
|
|
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
|
|
), |
|
|
), |
|
|
), |
|
|
subtitle: Text(item['commentaire'] ?? ''), |
|
|
subtitle: Text(item['commentaire'] ?? ''), |
|
|
trailing: Text( |
|
|
trailing: Text( |
|
|
@ -219,18 +229,18 @@ class _MenuPageState extends State<MenuPage> { |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
) |
|
|
) |
|
|
: Center(child: Text("Aucun menu disponible")), |
|
|
: const Center(child: Text("Aucun menu disponible")), |
|
|
), |
|
|
), |
|
|
Container( |
|
|
Container( |
|
|
width: double.infinity, |
|
|
width: double.infinity, |
|
|
padding: EdgeInsets.symmetric(vertical: 12), |
|
|
padding: const EdgeInsets.symmetric(vertical: 12), |
|
|
color: Colors.green[700], |
|
|
color: Colors.green[700], |
|
|
child: Center( |
|
|
child: Center( |
|
|
child: TextButton( |
|
|
child: TextButton( |
|
|
onPressed: _navigateToCart, // Navigation vers la page panier |
|
|
onPressed: _navigateToCart, // Navigation vers la page panier |
|
|
child: Text( |
|
|
child: Text( |
|
|
"Voir le panier (${_cart.length})", |
|
|
"Voir le panier (${_cart.length})", |
|
|
style: TextStyle(color: Colors.white, fontSize: 16), |
|
|
style: const TextStyle(color: Colors.white, fontSize: 16), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
@ -246,7 +256,7 @@ class _MenuPageState extends State<MenuPage> { |
|
|
child: GestureDetector( |
|
|
child: GestureDetector( |
|
|
onTap: () => changeCategory(id), |
|
|
onTap: () => changeCategory(id), |
|
|
child: Container( |
|
|
child: Container( |
|
|
padding: EdgeInsets.symmetric(vertical: 10), |
|
|
padding: const EdgeInsets.symmetric(vertical: 10), |
|
|
color: selected ? Colors.grey[300] : Colors.grey[100], |
|
|
color: selected ? Colors.grey[300] : Colors.grey[100], |
|
|
child: Center( |
|
|
child: Center( |
|
|
child: Text( |
|
|
child: Text( |
|
|
@ -268,10 +278,10 @@ class AddToCartModal extends StatefulWidget { |
|
|
final Function(dynamic, int, String) onAddToCart; |
|
|
final Function(dynamic, int, String) onAddToCart; |
|
|
|
|
|
|
|
|
const AddToCartModal({ |
|
|
const AddToCartModal({ |
|
|
Key? key, |
|
|
super.key, |
|
|
required this.item, |
|
|
required this.item, |
|
|
required this.onAddToCart, |
|
|
required this.onAddToCart, |
|
|
}) : super(key: key); |
|
|
}); |
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
|
State<AddToCartModal> createState() => _AddToCartModalState(); |
|
|
State<AddToCartModal> createState() => _AddToCartModalState(); |
|
|
@ -307,8 +317,8 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
return Dialog( |
|
|
return Dialog( |
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), |
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), |
|
|
child: Container( |
|
|
child: Container( |
|
|
padding: EdgeInsets.all(20), |
|
|
padding: const EdgeInsets.all(20), |
|
|
constraints: BoxConstraints(maxWidth: 400), |
|
|
constraints: const BoxConstraints(maxWidth: 400), |
|
|
child: Column( |
|
|
child: Column( |
|
|
mainAxisSize: MainAxisSize.min, |
|
|
mainAxisSize: MainAxisSize.min, |
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
@ -319,17 +329,20 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
children: [ |
|
|
children: [ |
|
|
Text( |
|
|
Text( |
|
|
widget.item['nom'] ?? 'Menu', |
|
|
widget.item['nom'] ?? 'Menu', |
|
|
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), |
|
|
style: const TextStyle( |
|
|
|
|
|
fontSize: 20, |
|
|
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
|
|
), |
|
|
), |
|
|
), |
|
|
IconButton( |
|
|
IconButton( |
|
|
onPressed: () => Navigator.of(context).pop(), |
|
|
onPressed: () => Navigator.of(context).pop(), |
|
|
icon: Icon(Icons.close), |
|
|
icon: const Icon(Icons.close), |
|
|
padding: EdgeInsets.zero, |
|
|
padding: EdgeInsets.zero, |
|
|
constraints: BoxConstraints(), |
|
|
constraints: const BoxConstraints(), |
|
|
), |
|
|
), |
|
|
], |
|
|
], |
|
|
), |
|
|
), |
|
|
SizedBox(height: 16), |
|
|
const SizedBox(height: 16), |
|
|
|
|
|
|
|
|
// Image placeholder |
|
|
// Image placeholder |
|
|
Container( |
|
|
Container( |
|
|
@ -345,7 +358,7 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
color: Colors.green[700], |
|
|
color: Colors.green[700], |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
SizedBox(height: 16), |
|
|
const SizedBox(height: 16), |
|
|
|
|
|
|
|
|
// Description |
|
|
// Description |
|
|
if (widget.item['commentaire'] != null && |
|
|
if (widget.item['commentaire'] != null && |
|
|
@ -354,13 +367,13 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
widget.item['commentaire'], |
|
|
widget.item['commentaire'], |
|
|
style: TextStyle(fontSize: 14, color: Colors.grey[600]), |
|
|
style: TextStyle(fontSize: 14, color: Colors.grey[600]), |
|
|
), |
|
|
), |
|
|
SizedBox(height: 16), |
|
|
const SizedBox(height: 16), |
|
|
|
|
|
|
|
|
// Prix unitaire |
|
|
// Prix unitaire |
|
|
Row( |
|
|
Row( |
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
children: [ |
|
|
children: [ |
|
|
Text( |
|
|
const Text( |
|
|
"Prix unitaire", |
|
|
"Prix unitaire", |
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500), |
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500), |
|
|
), |
|
|
), |
|
|
@ -374,14 +387,14 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
), |
|
|
), |
|
|
], |
|
|
], |
|
|
), |
|
|
), |
|
|
SizedBox(height: 20), |
|
|
const SizedBox(height: 20), |
|
|
|
|
|
|
|
|
// Quantité |
|
|
// Quantité |
|
|
Text( |
|
|
const Text( |
|
|
"Quantité", |
|
|
"Quantité", |
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500), |
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500), |
|
|
), |
|
|
), |
|
|
SizedBox(height: 8), |
|
|
const SizedBox(height: 8), |
|
|
Row( |
|
|
Row( |
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
children: [ |
|
|
children: [ |
|
|
@ -394,38 +407,41 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
: null, |
|
|
: null, |
|
|
icon: Icon(Icons.remove), |
|
|
icon: const Icon(Icons.remove), |
|
|
style: IconButton.styleFrom( |
|
|
style: IconButton.styleFrom( |
|
|
backgroundColor: Colors.grey[200], |
|
|
backgroundColor: Colors.grey[200], |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
SizedBox(width: 20), |
|
|
const SizedBox(width: 20), |
|
|
Text( |
|
|
Text( |
|
|
_quantity.toString(), |
|
|
_quantity.toString(), |
|
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), |
|
|
style: const TextStyle( |
|
|
|
|
|
fontSize: 18, |
|
|
|
|
|
fontWeight: FontWeight.bold, |
|
|
), |
|
|
), |
|
|
SizedBox(width: 20), |
|
|
), |
|
|
|
|
|
const SizedBox(width: 20), |
|
|
IconButton( |
|
|
IconButton( |
|
|
onPressed: () { |
|
|
onPressed: () { |
|
|
setState(() { |
|
|
setState(() { |
|
|
_quantity++; |
|
|
_quantity++; |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
icon: Icon(Icons.add), |
|
|
icon: const Icon(Icons.add), |
|
|
style: IconButton.styleFrom( |
|
|
style: IconButton.styleFrom( |
|
|
backgroundColor: Colors.grey[200], |
|
|
backgroundColor: Colors.grey[200], |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
], |
|
|
], |
|
|
), |
|
|
), |
|
|
SizedBox(height: 20), |
|
|
const SizedBox(height: 20), |
|
|
|
|
|
|
|
|
// Notes |
|
|
// Notes |
|
|
Text( |
|
|
const Text( |
|
|
"Notes (optionnel)", |
|
|
"Notes (optionnel)", |
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500), |
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500), |
|
|
), |
|
|
), |
|
|
SizedBox(height: 8), |
|
|
const SizedBox(height: 8), |
|
|
TextField( |
|
|
TextField( |
|
|
controller: _notesController, |
|
|
controller: _notesController, |
|
|
maxLines: 3, |
|
|
maxLines: 3, |
|
|
@ -434,15 +450,15 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
border: OutlineInputBorder( |
|
|
border: OutlineInputBorder( |
|
|
borderRadius: BorderRadius.circular(8), |
|
|
borderRadius: BorderRadius.circular(8), |
|
|
), |
|
|
), |
|
|
contentPadding: EdgeInsets.all(12), |
|
|
contentPadding: const EdgeInsets.all(12), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
SizedBox(height: 24), |
|
|
const SizedBox(height: 24), |
|
|
|
|
|
|
|
|
// Total et bouton d'ajout |
|
|
// Total et bouton d'ajout |
|
|
Container( |
|
|
Container( |
|
|
width: double.infinity, |
|
|
width: double.infinity, |
|
|
padding: EdgeInsets.all(16), |
|
|
padding: const EdgeInsets.all(16), |
|
|
decoration: BoxDecoration( |
|
|
decoration: BoxDecoration( |
|
|
color: Colors.grey[50], |
|
|
color: Colors.grey[50], |
|
|
borderRadius: BorderRadius.circular(12), |
|
|
borderRadius: BorderRadius.circular(12), |
|
|
@ -452,7 +468,7 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
Row( |
|
|
Row( |
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
children: [ |
|
|
children: [ |
|
|
Text( |
|
|
const Text( |
|
|
"Total", |
|
|
"Total", |
|
|
style: TextStyle( |
|
|
style: TextStyle( |
|
|
fontSize: 18, |
|
|
fontSize: 18, |
|
|
@ -469,7 +485,7 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
), |
|
|
), |
|
|
], |
|
|
], |
|
|
), |
|
|
), |
|
|
SizedBox(height: 16), |
|
|
const SizedBox(height: 16), |
|
|
SizedBox( |
|
|
SizedBox( |
|
|
width: double.infinity, |
|
|
width: double.infinity, |
|
|
child: ElevatedButton( |
|
|
child: ElevatedButton( |
|
|
@ -488,19 +504,19 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
"${widget.item['nom']} ajouté au panier", |
|
|
"${widget.item['nom']} ajouté au panier", |
|
|
), |
|
|
), |
|
|
backgroundColor: Colors.green, |
|
|
backgroundColor: Colors.green, |
|
|
duration: Duration(seconds: 2), |
|
|
duration: const Duration(seconds: 2), |
|
|
), |
|
|
), |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
style: ElevatedButton.styleFrom( |
|
|
style: ElevatedButton.styleFrom( |
|
|
backgroundColor: Colors.green[700], |
|
|
backgroundColor: Colors.green[700], |
|
|
foregroundColor: Colors.white, |
|
|
foregroundColor: Colors.white, |
|
|
padding: EdgeInsets.symmetric(vertical: 16), |
|
|
padding: const EdgeInsets.symmetric(vertical: 16), |
|
|
shape: RoundedRectangleBorder( |
|
|
shape: RoundedRectangleBorder( |
|
|
borderRadius: BorderRadius.circular(8), |
|
|
borderRadius: BorderRadius.circular(8), |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
child: Text( |
|
|
child: const Text( |
|
|
"Ajouter au panier", |
|
|
"Ajouter au panier", |
|
|
style: TextStyle( |
|
|
style: TextStyle( |
|
|
fontSize: 16, |
|
|
fontSize: 16, |
|
|
|