fix: overflow + owner managment error
This commit is contained in:
parent
86094b5d76
commit
f8f1849d9d
4 changed files with 309 additions and 281 deletions
|
|
@ -29,133 +29,135 @@ class _OwnerPopupState extends State<OwnerPopup> {
|
|||
listenable: widget.viewModel,
|
||||
builder: (context, child) => AlertDialog(
|
||||
title: Center(child: Text("Propriétaire du livre")),
|
||||
content: Column(
|
||||
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}",
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
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,
|
||||
label: Text("Rechercher un·e propriétaire"),
|
||||
dropdownMenuEntries: [
|
||||
for (var owner in widget.viewModel.owners!)
|
||||
DropdownMenuEntry(
|
||||
value: owner,
|
||||
label: "${owner.firstName} ${owner.lastName}",
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
(widget.viewModel.currentOwner == owner)
|
||||
? WidgetStatePropertyAll<Color>(
|
||||
theme.highlightColor,
|
||||
)
|
||||
: WidgetStatePropertyAll<Color>(
|
||||
theme.canvasColor,
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
(showNewOwner || widget.viewModel.owners!.isEmpty)
|
||||
? SizedBox()
|
||||
: DropdownMenu<Owner>(
|
||||
enableFilter: true,
|
||||
label: Text("Rechercher un·e propriétaire"),
|
||||
dropdownMenuEntries: [
|
||||
for (var owner in widget.viewModel.owners!)
|
||||
DropdownMenuEntry(
|
||||
value: owner,
|
||||
label: "${owner.firstName} ${owner.lastName}",
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
(widget.viewModel.currentOwner == owner)
|
||||
? WidgetStatePropertyAll<Color>(
|
||||
theme.highlightColor,
|
||||
)
|
||||
: WidgetStatePropertyAll<Color>(
|
||||
theme.canvasColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
initialSelection: widget.viewModel.currentOwner,
|
||||
onSelected: (Owner? owner) {
|
||||
widget.viewModel.currentOwner = owner;
|
||||
},
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
showNewOwner = !showNewOwner;
|
||||
});
|
||||
},
|
||||
child: Text(
|
||||
(showNewOwner) ? "Annuler" : "Ajouter un propriétaire",
|
||||
),
|
||||
),
|
||||
(!showNewOwner)
|
||||
? SizedBox()
|
||||
: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Nom",
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onSaved: (newValue) {
|
||||
setState(() {
|
||||
lastName = newValue;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Indiquez un nom";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Prénom",
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onSaved: (newValue) {
|
||||
setState(() {
|
||||
firstName = newValue;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Indiquez un prénom";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Contact",
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onSaved: (newValue) {
|
||||
setState(() {
|
||||
contact = newValue;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Indiquez un moyen de contact";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
widget.viewModel.currentOwner = widget.viewModel
|
||||
.addOwner(firstName!, lastName!, contact!);
|
||||
setState(() {
|
||||
showNewOwner = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Text("Créer"),
|
||||
),
|
||||
],
|
||||
initialSelection: widget.viewModel.currentOwner,
|
||||
onSelected: (Owner? owner) {
|
||||
widget.viewModel.currentOwner = owner;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
SizedBox(height: 20),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
showNewOwner = !showNewOwner;
|
||||
});
|
||||
},
|
||||
child: Text(
|
||||
(showNewOwner) ? "Annuler" : "Ajouter un propriétaire",
|
||||
),
|
||||
),
|
||||
(!showNewOwner)
|
||||
? SizedBox()
|
||||
: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Nom",
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onSaved: (newValue) {
|
||||
setState(() {
|
||||
lastName = newValue;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Indiquez un nom";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Prénom",
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onSaved: (newValue) {
|
||||
setState(() {
|
||||
firstName = newValue;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Indiquez un prénom";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Contact",
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onSaved: (newValue) {
|
||||
setState(() {
|
||||
contact = newValue;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Indiquez un moyen de contact";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
widget.viewModel.currentOwner = widget.viewModel
|
||||
.addOwner(firstName!, lastName!, contact!);
|
||||
setState(() {
|
||||
showNewOwner = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Text("Créer"),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
actions: [
|
||||
|
|
|
|||
Reference in a new issue