fix: changed owner managment

This commit is contained in:
Alzalia 2025-08-08 16:12:47 +02:00
parent f89efc3c52
commit d2cbb43bcb

View file

@ -22,6 +22,7 @@ class _OwnerPopupState extends State<OwnerPopup> {
String? firstName;
String? lastName;
String? contact;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
@ -68,18 +69,8 @@ class _OwnerPopupState extends State<OwnerPopup> {
onSelected: (Owner? owner) {
widget.viewModel.currentOwner = owner;
},
enableSearch: true,
),
SizedBox(height: 20),
TextButton(
onPressed: () {
setState(() {
showNewOwner = !showNewOwner;
});
},
child: Text(
(showNewOwner) ? "Annuler" : "Ajouter un propriétaire",
),
),
(!showNewOwner)
? SizedBox()
: Form(
@ -139,23 +130,6 @@ class _OwnerPopupState extends State<OwnerPopup> {
return null;
},
),
SizedBox(height: 10),
ElevatedButton(
onPressed: () async {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
await widget.viewModel.addOwner(
firstName!,
lastName!,
contact!,
);
setState(() {
showNewOwner = false;
});
}
},
child: Text("Créer"),
),
],
),
),
@ -166,7 +140,29 @@ class _OwnerPopupState extends State<OwnerPopup> {
actions: [
TextButton(
onPressed: () {
widget.onPressAccept(context);
setState(() {
showNewOwner = !showNewOwner;
});
},
child: Text((showNewOwner) ? "Annuler" : "Ajouter un propriétaire"),
),
TextButton(
onPressed: () async {
if (showNewOwner) {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
await widget.viewModel.addOwner(
firstName!,
lastName!,
contact!,
);
setState(() {
showNewOwner = false;
});
}
} else {
widget.onPressAccept(context);
}
},
child: Text("Valider"),
),