correction gestion menus
This commit is contained in:
parent
d4a5c60821
commit
63c64f3f4b
@ -26,16 +26,11 @@ class MenuPlat {
|
||||
class MenuCategory {
|
||||
final int id;
|
||||
final String nom;
|
||||
final String? description;
|
||||
|
||||
MenuCategory({required this.id, required this.nom, this.description});
|
||||
MenuCategory({required this.id, required this.nom});
|
||||
|
||||
factory MenuCategory.fromJson(Map<String, dynamic> json) {
|
||||
return MenuCategory(
|
||||
id: json['id'],
|
||||
nom: json['nom'],
|
||||
description: json['description'],
|
||||
);
|
||||
return MenuCategory(id: json['id'], nom: json['nom']);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -227,16 +222,13 @@ class _PlatEditPageState extends State<PlatEditPage> {
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
final result = await showDialog<
|
||||
List<MenuCategory>
|
||||
>(
|
||||
final result = await showDialog<MenuCategory?>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
// temp inside a StatefulBuilder so state changes refresh UI
|
||||
Set<int> temp =
|
||||
selectedCategories
|
||||
.map((e) => e.id)
|
||||
.toSet();
|
||||
MenuCategory? temp =
|
||||
selectedCategories.isNotEmpty
|
||||
? selectedCategories.first
|
||||
: null;
|
||||
|
||||
return StatefulBuilder(
|
||||
builder: (context, setStateDialog) {
|
||||
@ -249,18 +241,15 @@ class _PlatEditPageState extends State<PlatEditPage> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children:
|
||||
widget.categories.map((cat) {
|
||||
return CheckboxListTile(
|
||||
value: temp.contains(
|
||||
cat.id,
|
||||
),
|
||||
return RadioListTile<
|
||||
MenuCategory
|
||||
>(
|
||||
value: cat,
|
||||
groupValue: temp,
|
||||
title: Text(cat.nom),
|
||||
onChanged: (checked) {
|
||||
onChanged: (value) {
|
||||
setStateDialog(() {
|
||||
if (checked == true) {
|
||||
temp.add(cat.id);
|
||||
} else {
|
||||
temp.remove(cat.id);
|
||||
}
|
||||
temp = value;
|
||||
});
|
||||
},
|
||||
);
|
||||
@ -271,15 +260,11 @@ class _PlatEditPageState extends State<PlatEditPage> {
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
final newList =
|
||||
widget.categories
|
||||
.where(
|
||||
(cat) => temp.contains(
|
||||
cat.id,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
Navigator.pop(context, newList);
|
||||
if (temp != null) {
|
||||
Navigator.pop(context, temp);
|
||||
} else {
|
||||
Navigator.pop(context, null);
|
||||
}
|
||||
},
|
||||
child: const Text('OK'),
|
||||
),
|
||||
@ -290,37 +275,22 @@ class _PlatEditPageState extends State<PlatEditPage> {
|
||||
},
|
||||
);
|
||||
|
||||
if (result != null)
|
||||
setState(() => selectedCategories = result);
|
||||
if (result != null) {
|
||||
setState(() => selectedCategories = [result]);
|
||||
}
|
||||
},
|
||||
child: InputDecorator(
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Catégories *",
|
||||
labelText: "Catégorie *",
|
||||
border: OutlineInputBorder(gapPadding: 2),
|
||||
),
|
||||
child: Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: -8,
|
||||
children:
|
||||
selectedCategories.isEmpty
|
||||
? [
|
||||
const Text(
|
||||
"Aucune sélection",
|
||||
style: TextStyle(
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
]
|
||||
: selectedCategories
|
||||
.map(
|
||||
(c) => Chip(
|
||||
label: Text(c.nom),
|
||||
visualDensity:
|
||||
VisualDensity.compact,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
child:
|
||||
selectedCategories.isEmpty
|
||||
? const Text(
|
||||
"Aucune sélection",
|
||||
style: TextStyle(color: Colors.grey),
|
||||
)
|
||||
: Text(selectedCategories.first.nom),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@ -254,21 +254,12 @@ class _PlatsManagementScreenState extends State<PlatsManagementScreen> {
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
if (p.categories.isNotEmpty)
|
||||
Wrap(
|
||||
spacing: 4,
|
||||
runSpacing: 4,
|
||||
children:
|
||||
p.categories
|
||||
.map(
|
||||
(c) => CategoryChip(
|
||||
label: c.nom,
|
||||
color: Colors.black,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
if (p.categories.isEmpty)
|
||||
if (p.category != null)
|
||||
CategoryChip(
|
||||
label: p.category!.nom,
|
||||
color: Colors.black,
|
||||
)
|
||||
else
|
||||
const CategoryChip(
|
||||
label: "Catégorie",
|
||||
color: Colors.black,
|
||||
@ -378,8 +369,7 @@ class MenuPlat {
|
||||
final String? commentaire;
|
||||
final double prix;
|
||||
final String? ingredients;
|
||||
final int disponible = 1; // Default to true
|
||||
final List<MenuCategory> categories; // NOW A LIST!
|
||||
final MenuCategory? category; // single category
|
||||
|
||||
MenuPlat({
|
||||
required this.id,
|
||||
@ -387,7 +377,7 @@ class MenuPlat {
|
||||
this.commentaire,
|
||||
required this.prix,
|
||||
this.ingredients,
|
||||
required this.categories,
|
||||
this.category,
|
||||
});
|
||||
|
||||
factory MenuPlat.fromJson(Map<String, dynamic> json) {
|
||||
@ -404,12 +394,14 @@ class MenuPlat {
|
||||
commentaire: json['commentaire'],
|
||||
prix: parsePrix(json['prix']),
|
||||
ingredients: json['ingredients'],
|
||||
categories:
|
||||
(json['categories'] as List? ?? [])
|
||||
.map((c) => MenuCategory.fromJson(c))
|
||||
.toList(),
|
||||
category:
|
||||
json['category'] != null
|
||||
? MenuCategory.fromJson(json['category'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
get disponible => null;
|
||||
}
|
||||
|
||||
class CategoryChip extends StatelessWidget {
|
||||
@ -477,8 +469,7 @@ class _EditPlatDialogState extends State<EditPlatDialog> {
|
||||
prix = widget.plat.prix;
|
||||
var disponible = widget.plat.disponible;
|
||||
// cat = (widget.plat.categories) as MenuCategory?;
|
||||
cat =
|
||||
widget.plat.categories.isNotEmpty ? widget.plat.categories.first : null;
|
||||
cat = widget.plat.category;
|
||||
}
|
||||
|
||||
Future<void> submit() async {
|
||||
@ -542,6 +533,7 @@ class _EditPlatDialogState extends State<EditPlatDialog> {
|
||||
isExpanded: true,
|
||||
items:
|
||||
widget.categories
|
||||
.toSet()
|
||||
.map(
|
||||
(c) => DropdownMenuItem(value: c, child: Text(c.nom)),
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user