|
|
|
@ -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), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
|