|
|
@ -9,7 +9,8 @@ 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}) : super(key: key); |
|
|
const MenuPage({Key? key, required this.tableId, required this.personne}) |
|
|
|
|
|
: super(key: key); |
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
|
State<MenuPage> createState() => _MenuPageState(); |
|
|
State<MenuPage> createState() => _MenuPageState(); |
|
|
@ -29,13 +30,16 @@ class _MenuPageState extends State<MenuPage> { |
|
|
|
|
|
|
|
|
Future<void> fetchCategories() async { |
|
|
Future<void> fetchCategories() async { |
|
|
try { |
|
|
try { |
|
|
final url = Uri.parse("https://restaurant.careeracademy.mg/api/menu-categories"); |
|
|
final url = Uri.parse( |
|
|
|
|
|
"https://restaurant.careeracademy.mg/api/menu-categories", |
|
|
|
|
|
); |
|
|
final response = await http.get(url); |
|
|
final response = await http.get(url); |
|
|
|
|
|
|
|
|
if (response.statusCode == 200) { |
|
|
if (response.statusCode == 200) { |
|
|
final jsonResponse = json.decode(response.body); |
|
|
final jsonResponse = json.decode(response.body); |
|
|
|
|
|
|
|
|
final categoriesList = (jsonResponse['data']?['categories'] ?? []) as List<dynamic>; |
|
|
final categoriesList = |
|
|
|
|
|
(jsonResponse['data']?['categories'] ?? []) as List<dynamic>; |
|
|
|
|
|
|
|
|
setState(() { |
|
|
setState(() { |
|
|
_categories = categoriesList; |
|
|
_categories = categoriesList; |
|
|
@ -54,15 +58,16 @@ class _MenuPageState extends State<MenuPage> { |
|
|
|
|
|
|
|
|
Future<void> fetchMenus(int categoryId) async { |
|
|
Future<void> fetchMenus(int categoryId) async { |
|
|
try { |
|
|
try { |
|
|
final url = Uri.parse("https://restaurant.careeracademy.mg/api/menus/category/$categoryId?disponible=true"); |
|
|
final url = Uri.parse( |
|
|
|
|
|
"https://restaurant.careeracademy.mg/api/menus/category/$categoryId?disponible=true", |
|
|
|
|
|
); |
|
|
final response = await http.get(url); |
|
|
final response = await http.get(url); |
|
|
|
|
|
|
|
|
if (response.statusCode == 200) { |
|
|
if (response.statusCode == 200) { |
|
|
final jsonResponse = json.decode(response.body); |
|
|
final jsonResponse = json.decode(response.body); |
|
|
|
|
|
|
|
|
final List<dynamic> menusList = jsonResponse is List |
|
|
final List<dynamic> menusList = |
|
|
? jsonResponse |
|
|
jsonResponse is List ? jsonResponse : (jsonResponse['data'] ?? []); |
|
|
: (jsonResponse['data'] ?? []); |
|
|
|
|
|
|
|
|
|
|
|
setState(() { |
|
|
setState(() { |
|
|
_menus = menusList; |
|
|
_menus = menusList; |
|
|
@ -99,10 +104,7 @@ class _MenuPageState extends State<MenuPage> { |
|
|
showDialog( |
|
|
showDialog( |
|
|
context: context, |
|
|
context: context, |
|
|
builder: (BuildContext context) { |
|
|
builder: (BuildContext context) { |
|
|
return AddToCartModal( |
|
|
return AddToCartModal(item: item, onAddToCart: addToCart); |
|
|
item: item, |
|
|
|
|
|
onAddToCart: addToCart, |
|
|
|
|
|
); |
|
|
|
|
|
}, |
|
|
}, |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
@ -112,10 +114,13 @@ class _MenuPageState extends State<MenuPage> { |
|
|
Navigator.push( |
|
|
Navigator.push( |
|
|
context, |
|
|
context, |
|
|
MaterialPageRoute( |
|
|
MaterialPageRoute( |
|
|
builder: (context) => CartPage( |
|
|
builder: |
|
|
|
|
|
(context) => CartPage( |
|
|
tableId: widget.tableId, |
|
|
tableId: widget.tableId, |
|
|
personne: widget.personne, |
|
|
personne: widget.personne, |
|
|
cartItems: List.from(_cart), // Copie de la liste pour éviter les modifications |
|
|
cartItems: List.from( |
|
|
|
|
|
_cart, |
|
|
|
|
|
), // Copie de la liste pour éviter les modifications |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
).then((_) { |
|
|
).then((_) { |
|
|
@ -163,14 +168,16 @@ class _MenuPageState extends State<MenuPage> { |
|
|
if (_categories.isNotEmpty) |
|
|
if (_categories.isNotEmpty) |
|
|
Row( |
|
|
Row( |
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
|
children: _categories.map<Widget>((cat) { |
|
|
children: |
|
|
|
|
|
_categories.map<Widget>((cat) { |
|
|
return buildCategoryButton(cat['nom'], cat['id']); |
|
|
return buildCategoryButton(cat['nom'], cat['id']); |
|
|
}).toList(), |
|
|
}).toList(), |
|
|
) |
|
|
) |
|
|
else |
|
|
else |
|
|
Center(child: CircularProgressIndicator()), |
|
|
Center(child: CircularProgressIndicator()), |
|
|
Expanded( |
|
|
Expanded( |
|
|
child: _menus.isNotEmpty |
|
|
child: |
|
|
|
|
|
_menus.isNotEmpty |
|
|
? ListView.builder( |
|
|
? ListView.builder( |
|
|
itemCount: _menus.length, |
|
|
itemCount: _menus.length, |
|
|
itemBuilder: (context, index) { |
|
|
itemBuilder: (context, index) { |
|
|
@ -178,7 +185,10 @@ class _MenuPageState extends State<MenuPage> { |
|
|
return Card( |
|
|
return Card( |
|
|
margin: EdgeInsets.all(8), |
|
|
margin: EdgeInsets.all(8), |
|
|
child: ListTile( |
|
|
child: ListTile( |
|
|
onTap: () => showAddToCartModal(item), // Clic sur tout l'item |
|
|
onTap: |
|
|
|
|
|
() => showAddToCartModal( |
|
|
|
|
|
item, |
|
|
|
|
|
), // Clic sur tout l'item |
|
|
leading: Container( |
|
|
leading: Container( |
|
|
width: 60, |
|
|
width: 60, |
|
|
height: 60, |
|
|
height: 60, |
|
|
@ -198,7 +208,7 @@ class _MenuPageState extends State<MenuPage> { |
|
|
), |
|
|
), |
|
|
subtitle: Text(item['commentaire'] ?? ''), |
|
|
subtitle: Text(item['commentaire'] ?? ''), |
|
|
trailing: Text( |
|
|
trailing: Text( |
|
|
"${formatPrix(item['prix'])} €", |
|
|
"${formatPrix(item['prix'])} MGA", |
|
|
style: TextStyle( |
|
|
style: TextStyle( |
|
|
color: Colors.green[700], |
|
|
color: Colors.green[700], |
|
|
fontWeight: FontWeight.bold, |
|
|
fontWeight: FontWeight.bold, |
|
|
@ -295,9 +305,7 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
@override |
|
|
@override |
|
|
Widget build(BuildContext context) { |
|
|
Widget build(BuildContext context) { |
|
|
return Dialog( |
|
|
return Dialog( |
|
|
shape: RoundedRectangleBorder( |
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), |
|
|
borderRadius: BorderRadius.circular(16), |
|
|
|
|
|
), |
|
|
|
|
|
child: Container( |
|
|
child: Container( |
|
|
padding: EdgeInsets.all(20), |
|
|
padding: EdgeInsets.all(20), |
|
|
constraints: BoxConstraints(maxWidth: 400), |
|
|
constraints: BoxConstraints(maxWidth: 400), |
|
|
@ -311,10 +319,7 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
children: [ |
|
|
children: [ |
|
|
Text( |
|
|
Text( |
|
|
widget.item['nom'] ?? 'Menu', |
|
|
widget.item['nom'] ?? 'Menu', |
|
|
style: TextStyle( |
|
|
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), |
|
|
fontSize: 20, |
|
|
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
), |
|
|
IconButton( |
|
|
IconButton( |
|
|
onPressed: () => Navigator.of(context).pop(), |
|
|
onPressed: () => Navigator.of(context).pop(), |
|
|
@ -343,13 +348,11 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
SizedBox(height: 16), |
|
|
SizedBox(height: 16), |
|
|
|
|
|
|
|
|
// Description |
|
|
// Description |
|
|
if (widget.item['commentaire'] != null && widget.item['commentaire'].toString().isNotEmpty) |
|
|
if (widget.item['commentaire'] != null && |
|
|
|
|
|
widget.item['commentaire'].toString().isNotEmpty) |
|
|
Text( |
|
|
Text( |
|
|
widget.item['commentaire'], |
|
|
widget.item['commentaire'], |
|
|
style: TextStyle( |
|
|
style: TextStyle(fontSize: 14, color: Colors.grey[600]), |
|
|
fontSize: 14, |
|
|
|
|
|
color: Colors.grey[600], |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
), |
|
|
SizedBox(height: 16), |
|
|
SizedBox(height: 16), |
|
|
|
|
|
|
|
|
@ -359,13 +362,10 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
children: [ |
|
|
children: [ |
|
|
Text( |
|
|
Text( |
|
|
"Prix unitaire", |
|
|
"Prix unitaire", |
|
|
style: TextStyle( |
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500), |
|
|
fontSize: 16, |
|
|
|
|
|
fontWeight: FontWeight.w500, |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
), |
|
|
Text( |
|
|
Text( |
|
|
"${formatPrix(widget.item['prix'])} €", |
|
|
"${formatPrix(widget.item['prix'])} MGA", |
|
|
style: TextStyle( |
|
|
style: TextStyle( |
|
|
fontSize: 16, |
|
|
fontSize: 16, |
|
|
fontWeight: FontWeight.bold, |
|
|
fontWeight: FontWeight.bold, |
|
|
@ -379,21 +379,21 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
// Quantité |
|
|
// Quantité |
|
|
Text( |
|
|
Text( |
|
|
"Quantité", |
|
|
"Quantité", |
|
|
style: TextStyle( |
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500), |
|
|
fontSize: 16, |
|
|
|
|
|
fontWeight: FontWeight.w500, |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
), |
|
|
SizedBox(height: 8), |
|
|
SizedBox(height: 8), |
|
|
Row( |
|
|
Row( |
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
children: [ |
|
|
children: [ |
|
|
IconButton( |
|
|
IconButton( |
|
|
onPressed: _quantity > 1 ? () { |
|
|
onPressed: |
|
|
|
|
|
_quantity > 1 |
|
|
|
|
|
? () { |
|
|
setState(() { |
|
|
setState(() { |
|
|
_quantity--; |
|
|
_quantity--; |
|
|
}); |
|
|
}); |
|
|
} : null, |
|
|
} |
|
|
|
|
|
: null, |
|
|
icon: Icon(Icons.remove), |
|
|
icon: Icon(Icons.remove), |
|
|
style: IconButton.styleFrom( |
|
|
style: IconButton.styleFrom( |
|
|
backgroundColor: Colors.grey[200], |
|
|
backgroundColor: Colors.grey[200], |
|
|
@ -402,10 +402,7 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
SizedBox(width: 20), |
|
|
SizedBox(width: 20), |
|
|
Text( |
|
|
Text( |
|
|
_quantity.toString(), |
|
|
_quantity.toString(), |
|
|
style: TextStyle( |
|
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), |
|
|
fontSize: 18, |
|
|
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
), |
|
|
SizedBox(width: 20), |
|
|
SizedBox(width: 20), |
|
|
IconButton( |
|
|
IconButton( |
|
|
@ -426,10 +423,7 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
// Notes |
|
|
// Notes |
|
|
Text( |
|
|
Text( |
|
|
"Notes (optionnel)", |
|
|
"Notes (optionnel)", |
|
|
style: TextStyle( |
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500), |
|
|
fontSize: 16, |
|
|
|
|
|
fontWeight: FontWeight.w500, |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
), |
|
|
SizedBox(height: 8), |
|
|
SizedBox(height: 8), |
|
|
TextField( |
|
|
TextField( |
|
|
@ -466,7 +460,7 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
Text( |
|
|
Text( |
|
|
"${calculateTotal().toStringAsFixed(2)} €", |
|
|
"${calculateTotal().toStringAsFixed(2)} MGA", |
|
|
style: TextStyle( |
|
|
style: TextStyle( |
|
|
fontSize: 18, |
|
|
fontSize: 18, |
|
|
fontWeight: FontWeight.bold, |
|
|
fontWeight: FontWeight.bold, |
|
|
@ -490,7 +484,9 @@ class _AddToCartModalState extends State<AddToCartModal> { |
|
|
// Afficher un snackbar de confirmation |
|
|
// Afficher un snackbar de confirmation |
|
|
ScaffoldMessenger.of(context).showSnackBar( |
|
|
ScaffoldMessenger.of(context).showSnackBar( |
|
|
SnackBar( |
|
|
SnackBar( |
|
|
content: Text("${widget.item['nom']} ajouté au panier"), |
|
|
content: Text( |
|
|
|
|
|
"${widget.item['nom']} ajouté au panier", |
|
|
|
|
|
), |
|
|
backgroundColor: Colors.green, |
|
|
backgroundColor: Colors.green, |
|
|
duration: Duration(seconds: 2), |
|
|
duration: Duration(seconds: 2), |
|
|
), |
|
|
), |
|
|
|