feat: add an owner + sell screen

This commit is contained in:
Alzalia 2025-08-08 19:42:50 +02:00
parent d2cbb43bcb
commit 073f8bd334
15 changed files with 354 additions and 82 deletions

View file

@ -18,6 +18,7 @@ class OwnerPopup extends StatefulWidget {
class _OwnerPopupState extends State<OwnerPopup> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final TextEditingController searchController = TextEditingController();
bool showNewOwner = false;
String? firstName;
String? lastName;
@ -25,6 +26,9 @@ class _OwnerPopupState extends State<OwnerPopup> {
@override
Widget build(BuildContext context) {
searchController.text = (widget.viewModel.currentOwner == null)
? ""
: "${widget.viewModel.currentOwner!.firstName} ${widget.viewModel.currentOwner!.lastName}";
final theme = Theme.of(context);
return ListenableBuilder(
listenable: widget.viewModel,
@ -35,19 +39,14 @@ class _OwnerPopupState extends State<OwnerPopup> {
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Center(
child: Text(
(widget.viewModel.currentOwner == null)
? "Choix actuel : aucun"
: "Choix actuel : ${widget.viewModel.currentOwner!.firstName} ${widget.viewModel.currentOwner!.lastName}",
),
),
SizedBox(height: 5),
(showNewOwner || widget.viewModel.owners!.isEmpty)
? SizedBox()
: DropdownMenu<Owner>(
enableFilter: true,
controller: searchController,
label: Text("Rechercher un·e propriétaire"),
requestFocusOnTap: true,
dropdownMenuEntries: [
for (var owner in widget.viewModel.owners!)
DropdownMenuEntry(
@ -65,7 +64,6 @@ class _OwnerPopupState extends State<OwnerPopup> {
),
),
],
initialSelection: widget.viewModel.currentOwner,
onSelected: (Owner? owner) {
widget.viewModel.currentOwner = owner;
},
@ -151,6 +149,7 @@ class _OwnerPopupState extends State<OwnerPopup> {
if (showNewOwner) {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
debugPrint("\n\n\n\n(1) SENDING REQUEST\n\n\n\n");
await widget.viewModel.addOwner(
firstName!,
lastName!,
@ -160,9 +159,8 @@ class _OwnerPopupState extends State<OwnerPopup> {
showNewOwner = false;
});
}
} else {
widget.onPressAccept(context);
}
widget.onPressAccept(context);
},
child: Text("Valider"),
),