feat: add a book by scanning
This commit is contained in:
parent
72fd0b66a9
commit
981dce5bfe
14 changed files with 264 additions and 59 deletions
|
|
@ -75,6 +75,8 @@ class _AddPageState extends State<AddPage> {
|
|||
);
|
||||
break;
|
||||
case Error():
|
||||
debugPrintStack();
|
||||
debugPrint(result.error.toString());
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Erreur : ${result.error}"),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:seshat/domain/models/bal.dart';
|
||||
import 'package:seshat/domain/models/book.dart';
|
||||
import 'package:seshat/ui/add_page/view_model/add_view_model.dart';
|
||||
import 'package:seshat/utils/result.dart';
|
||||
|
||||
class ConfirmationPopup extends StatefulWidget {
|
||||
const ConfirmationPopup({
|
||||
|
|
@ -22,7 +26,7 @@ class ConfirmationPopup extends StatefulWidget {
|
|||
|
||||
class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
num price = 0;
|
||||
double price = 0;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
|
@ -67,7 +71,7 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
|||
text: "Prix à neuf : ",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
TextSpan(text: widget.book.priceNew),
|
||||
TextSpan(text: widget.book.priceNew.replaceAll("EUR", "€")),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
@ -89,7 +93,7 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
|||
return null;
|
||||
},
|
||||
onSaved: (newValue) {
|
||||
price = num.parse(newValue!);
|
||||
price = double.parse(newValue!);
|
||||
},
|
||||
)
|
||||
: SizedBox(),
|
||||
|
|
@ -111,32 +115,57 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
|||
child: Text("Annuler"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
switch (widget.viewModel.askPrice) {
|
||||
case true:
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
onPressed: () async {
|
||||
var result = await widget.viewModel.sendBook(
|
||||
widget.book,
|
||||
widget.viewModel.currentOwner!,
|
||||
Bal(id: 1),
|
||||
price,
|
||||
);
|
||||
switch (result) {
|
||||
case Ok():
|
||||
switch (widget.viewModel.askPrice) {
|
||||
case true:
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
"\"${widget.book.title}\" ($price€) a bien été enregistré",
|
||||
),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
widget.exitPopup(context);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case false:
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
"\"${widget.book.title}\" (PL) a bien été enregistré",
|
||||
),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
widget.exitPopup(context);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case Error():
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
"\"${widget.book.title}\" ($price) a bien été enregistré",
|
||||
"Une erreur est survenue : ${result.error}",
|
||||
),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
widget.exitPopup(context);
|
||||
}
|
||||
break;
|
||||
case false:
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
"\"${widget.book.title}\" (PL) a bien été enregistré",
|
||||
),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
widget.exitPopup(context);
|
||||
}
|
||||
},
|
||||
child: Text("Valider"),
|
||||
|
|
|
|||
Reference in a new issue