fix: overflow + owner managment error

This commit is contained in:
Alzalia 2025-08-05 15:50:37 +02:00
parent 86094b5d76
commit f8f1849d9d
4 changed files with 309 additions and 281 deletions

View file

@ -38,6 +38,18 @@ class _AddPageState extends State<AddPage> {
MobileScanner(
controller: controller,
onDetect: (barcodes) async {
if (widget.viewModel.currentOwner == null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"Attention : vous devez choisir un·e propriétaire",
),
behavior: SnackBarBehavior.floating,
),
);
return;
}
void setPrice(num newPrice) async {
setState(() {
price = newPrice;
@ -68,62 +80,77 @@ class _AddPageState extends State<AddPage> {
},
),
SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: Card(
margin: EdgeInsets.symmetric(horizontal: 50),
child: Column(
children: [
ListenableBuilder(
listenable: widget.viewModel,
builder: (context, child) => ListTile(
leading: Icon(Icons.person),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Center(
child: Card(
margin: EdgeInsets.symmetric(horizontal: 50),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListenableBuilder(
listenable: widget.viewModel,
builder: (context, child) => ListTile(
leading: Icon(Icons.person),
title: TextButton(
child: Text(
(widget.viewModel.currentOwner == null)
? "Aucun"
: "${widget.viewModel.currentOwner!.firstName} ${widget.viewModel.currentOwner!.lastName}",
),
onPressed: () => _ownerDialogBuilder(
context,
controller,
widget.viewModel,
),
),
),
),
ListTile(
leading: Icon(Icons.attach_money),
title: TextButton(
child: Text(
(widget.viewModel.currentOwner == null)
? "Aucun"
: "${widget.viewModel.currentOwner!.firstName} ${widget.viewModel.currentOwner!.lastName}",
),
onPressed: () => _ownerDialogBuilder(
context,
controller,
widget.viewModel,
(widget.viewModel.askPrice)
? "Demander à chaque fois"
: "Prix libre toujours",
),
onPressed: () {
setState(() {
widget.viewModel.askPrice =
!widget.viewModel.askPrice;
});
},
),
),
),
ListTile(
leading: Icon(Icons.attach_money),
title: TextButton(
child: Text(
(widget.viewModel.askPrice)
? "Demander à chaque fois"
: "Prix libre toujours",
),
onPressed: () {
setState(() {
widget.viewModel.askPrice =
!widget.viewModel.askPrice;
});
},
),
),
],
],
),
),
),
),
Expanded(child: SizedBox()),
SvgPicture.asset('assets/scan-overlay.svg'),
Expanded(child: SizedBox()),
TextButton(
style: ButtonStyle(
backgroundColor: WidgetStatePropertyAll(theme.cardColor),
SizedBox(height: 100),
SvgPicture.asset('assets/scan-overlay.svg'),
],
),
),
),
SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Center(
child: TextButton(
style: ButtonStyle(
backgroundColor: WidgetStatePropertyAll(theme.cardColor),
),
onPressed: () => _formDialogBuilder(
context,
controller,
widget.viewModel,
),
child: Text("Enregistrer manuellement"),
),
onPressed: () =>
_formDialogBuilder(context, controller, widget.viewModel),
child: Text("Enregistrer manuellement"),
),
],
),

View file

@ -30,69 +30,71 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
title: Text("Prix"),
content: Form(
key: _formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
RichText(
text: TextSpan(
style: theme.textTheme.bodyMedium,
children: [
TextSpan(
text: "Titre : ",
style: TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(text: widget.book.title),
],
),
),
RichText(
text: TextSpan(
style: theme.textTheme.bodyMedium,
children: [
TextSpan(
text: "Auteur·ice : ",
style: TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(text: widget.book.author),
],
),
),
RichText(
text: TextSpan(
style: theme.textTheme.bodyMedium,
children: [
TextSpan(
text: "Prix à neuf : ",
style: TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(text: widget.book.priceNew),
],
),
),
SizedBox(height: 10),
(widget.viewModel.askPrice)
? TextFormField(
decoration: InputDecoration(
labelText: "Prix",
border: OutlineInputBorder(),
suffixText: "",
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
RichText(
text: TextSpan(
style: theme.textTheme.bodyMedium,
children: [
TextSpan(
text: "Titre : ",
style: TextStyle(fontWeight: FontWeight.bold),
),
keyboardType: TextInputType.number,
validator: (value) {
if (value == null || value.isEmpty) {
return "Indiquez un prix";
} else if (num.tryParse(value) == null) {
return "Le prix doit être un nombre";
}
return null;
},
onSaved: (newValue) {
price = num.parse(newValue!);
},
)
: SizedBox(),
],
TextSpan(text: widget.book.title),
],
),
),
RichText(
text: TextSpan(
style: theme.textTheme.bodyMedium,
children: [
TextSpan(
text: "Auteur·ice : ",
style: TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(text: widget.book.author),
],
),
),
RichText(
text: TextSpan(
style: theme.textTheme.bodyMedium,
children: [
TextSpan(
text: "Prix à neuf : ",
style: TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(text: widget.book.priceNew),
],
),
),
SizedBox(height: 10),
(widget.viewModel.askPrice)
? TextFormField(
decoration: InputDecoration(
labelText: "Prix",
border: OutlineInputBorder(),
suffixText: "",
),
keyboardType: TextInputType.number,
validator: (value) {
if (value == null || value.isEmpty) {
return "Indiquez un prix";
} else if (num.tryParse(value) == null) {
return "Le prix doit être un nombre";
}
return null;
},
onSaved: (newValue) {
price = num.parse(newValue!);
},
)
: SizedBox(),
],
),
),
),
actions: [

View file

@ -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: [