feat: complete sell

This commit is contained in:
alzalia1 2025-08-15 14:48:27 +02:00
parent b4375fbaa2
commit bee5e05296
5 changed files with 144 additions and 38 deletions

View file

@ -17,6 +17,8 @@ class SellPage extends StatefulWidget {
}
class _SellPageState extends State<SellPage> {
TextEditingController price = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
@ -70,52 +72,60 @@ class _SellPageState extends State<SellPage> {
),
SizedBox(height: 15),
Expanded(
child: ListView(
children: [
(widget.viewModel.scannedBooks.isEmpty)
? Center(child: Text("Aucun"))
: SizedBox(),
for (BookStack book in widget.viewModel.soldBooks)
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 15,
),
child: Card(
child: ListTile(
leading: Text(
"${book.instance.price.toString()}",
style: TextStyle(fontSize: 30),
child: (widget.viewModel.isSendingSell)
? Center(child: CircularProgressIndicator())
: ListView(
children: [
(widget.viewModel.scannedBooks.isEmpty)
? Center(child: Text("Aucun"))
: SizedBox(),
for (BookStack book
in widget.viewModel.soldBooks)
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 15,
),
child: Card(
child: ListTile(
leading: Text(
"${book.instance.price.toString()}",
style: TextStyle(fontSize: 30),
),
title: Text(
"${book.book.title} · ${book.book.author}",
),
subtitle: Text(
"${book.owner.firstName} ${book.owner.lastName} (${book.shortId()})",
),
trailing: IconButton(
onPressed: () {
widget.viewModel.deleteBook(
book.instance.id,
);
},
icon: Icon(Icons.delete),
),
),
),
),
title: Text(
"${book.book.title} · ${book.book.author}",
),
subtitle: Text(
"${book.owner.firstName} ${book.owner.lastName} (${book.shortId()})",
),
trailing: IconButton(
onPressed: () {
widget.viewModel.deleteBook(
book.instance.id,
);
},
icon: Icon(Icons.delete),
),
),
),
],
),
],
),
),
SizedBox(height: 40),
Text("Montant minimum à payer : 20€"),
Text(
"Montant minimum à payer : ${widget.viewModel.minimumAmount.toString()}",
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 60.0),
child: SizedBox(
child: TextField(
controller: price,
decoration: InputDecoration(
labelText: "Argent reçu",
hintText:
"Utilisez un point (.) pour les virgules (,)",
helperText:
"L'argent reçu sera réparti automatiquement",
"L'argent reçu sera réparti automatiquement.",
suffixText: "",
border: OutlineInputBorder(),
),
@ -129,7 +139,40 @@ class _SellPageState extends State<SellPage> {
children: [
IconButton(
onPressed: () {
widget.viewModel.sendSell();
if (double.tryParse(price.text) == null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"Veuillez indiquer un prix de vente valide",
),
behavior: SnackBarBehavior.floating,
),
);
return;
} else if (double.parse(price.text) <
widget.viewModel.minimumAmount) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"Le prix de vente est inférieur au montant minimum",
),
behavior: SnackBarBehavior.floating,
),
);
return;
}
widget.viewModel.sendSell(
double.parse(price.text),
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"La vente a bien été enregistrée.",
),
behavior: SnackBarBehavior.floating,
),
);
return;
},
icon: Icon(Icons.check),
style: ButtonStyle(