fix: some error managment and a whole feature missing
This commit is contained in:
parent
dad000a1b9
commit
6bcc3a7e88
5 changed files with 192 additions and 140 deletions
|
|
@ -125,8 +125,7 @@ class AddViewModel extends ChangeNotifier {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// Retrieves the book associated with an ean through a [barcode]
|
/// Retrieves the book associated with an ean through a [barcode]
|
||||||
Future<Result<Book>> scanBook(BarcodeCapture barcode) async {
|
Future<Result<Book>> scanBook(String ean) async {
|
||||||
var ean = barcode.barcodes.first.rawValue!;
|
|
||||||
var result = await _bookRepository.getBookByEAN(ean);
|
var result = await _bookRepository.getBookByEAN(ean);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,23 +22,20 @@ class AddPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AddPageState extends State<AddPage> {
|
class _AddPageState extends State<AddPage> {
|
||||||
num? price;
|
final MobileScannerController scannerController = MobileScannerController(
|
||||||
final MobileScannerController controller = MobileScannerController(
|
|
||||||
formats: [BarcodeFormat.ean13],
|
formats: [BarcodeFormat.ean13],
|
||||||
detectionTimeoutMs: 1000,
|
detectionTimeoutMs: 1000,
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
controller.dispose();
|
scannerController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
// return Consumer<TabScreen>(
|
|
||||||
// builder: (context, screen, child) {
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
bottomNavigationBar: AppNavigationBar(startIndex: 1),
|
bottomNavigationBar: AppNavigationBar(startIndex: 1),
|
||||||
body: ListenableBuilder(
|
body: ListenableBuilder(
|
||||||
|
|
@ -78,60 +75,37 @@ class _AddPageState extends State<AddPage> {
|
||||||
children: [
|
children: [
|
||||||
ColoredBox(color: Colors.black),
|
ColoredBox(color: Colors.black),
|
||||||
MobileScanner(
|
MobileScanner(
|
||||||
controller: controller,
|
controller: scannerController,
|
||||||
onDetect: (barcodes) async {
|
onDetect: (barcodes) async {
|
||||||
if (barcodes.barcodes.isEmpty) {
|
if (barcodes.barcodes.isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.viewModel.currentOwner == null) {
|
if (widget.viewModel.currentOwner == null) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
_showMissingOwnerSnackBar(
|
||||||
SnackBar(
|
context,
|
||||||
content: Text(
|
scannerController,
|
||||||
"Attention : vous devez choisir un·e propriétaire",
|
widget.viewModel,
|
||||||
),
|
|
||||||
behavior: SnackBarBehavior.floating,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPrice(num newPrice) async {
|
_scanEan(
|
||||||
setState(() {
|
context,
|
||||||
price = newPrice;
|
widget.viewModel,
|
||||||
});
|
barcodes.barcodes.first.rawValue!,
|
||||||
}
|
scannerController,
|
||||||
|
|
||||||
Result<Book> result = await widget.viewModel.scanBook(
|
|
||||||
barcodes,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
switch (result) {
|
|
||||||
case Ok():
|
|
||||||
await _confirmationDialogBuilder(
|
|
||||||
context,
|
|
||||||
setPrice,
|
|
||||||
controller,
|
|
||||||
widget.viewModel,
|
|
||||||
result.value,
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case Error():
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text("Erreur : ${result.error}"),
|
|
||||||
behavior: SnackBarBehavior.floating,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
Center(
|
Center(
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
'assets/scan-overlay.svg',
|
'assets/scan-overlay.svg',
|
||||||
height: (MediaQuery.sizeOf(context).height / 5) * 2,
|
height: (MediaQuery.sizeOf(context).height / 5) * 2,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
SafeArea(
|
SafeArea(
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|
@ -155,7 +129,7 @@ class _AddPageState extends State<AddPage> {
|
||||||
),
|
),
|
||||||
onPressed: () => _ownerDialogBuilder(
|
onPressed: () => _ownerDialogBuilder(
|
||||||
context,
|
context,
|
||||||
controller,
|
scannerController,
|
||||||
widget.viewModel,
|
widget.viewModel,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -184,6 +158,7 @@ class _AddPageState extends State<AddPage> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
SafeArea(
|
SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
|
@ -197,19 +172,17 @@ class _AddPageState extends State<AddPage> {
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (widget.viewModel.currentOwner == null) {
|
if (widget.viewModel.currentOwner == null) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
_showMissingOwnerSnackBar(
|
||||||
SnackBar(
|
context,
|
||||||
content: Text(
|
scannerController,
|
||||||
"Attention : vous devez choisir un·e propriétaire",
|
widget.viewModel,
|
||||||
),
|
|
||||||
behavior: SnackBarBehavior.floating,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_formDialogBuilder(
|
_formDialogBuilder(
|
||||||
context,
|
context,
|
||||||
controller,
|
scannerController,
|
||||||
widget.viewModel,
|
widget.viewModel,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
@ -231,18 +204,71 @@ class _AddPageState extends State<AddPage> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _scanEan(
|
||||||
|
BuildContext context,
|
||||||
|
AddViewModel viewModel,
|
||||||
|
String ean,
|
||||||
|
MobileScannerController scannerController, {
|
||||||
|
Function(BuildContext)? leaveLastPopup,
|
||||||
|
}) async {
|
||||||
|
Result<Book> result = await viewModel.scanBook(ean);
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
if (leaveLastPopup != null) {
|
||||||
|
leaveLastPopup(context);
|
||||||
|
}
|
||||||
|
switch (result) {
|
||||||
|
case Ok():
|
||||||
|
await _confirmationDialogBuilder(
|
||||||
|
context,
|
||||||
|
scannerController,
|
||||||
|
viewModel,
|
||||||
|
result.value,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case Error():
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text("Erreur : ${result.error}"),
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showMissingOwnerSnackBar(
|
||||||
|
BuildContext context,
|
||||||
|
MobileScannerController scannerController,
|
||||||
|
AddViewModel viewModel,
|
||||||
|
) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text("Attention : vous devez choisir un·e propriétaire"),
|
||||||
|
duration: Duration(seconds: 4),
|
||||||
|
action: SnackBarAction(
|
||||||
|
label: "Choisir",
|
||||||
|
onPressed: () =>
|
||||||
|
_ownerDialogBuilder(context, scannerController, viewModel),
|
||||||
|
),
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _confirmationDialogBuilder(
|
Future<void> _confirmationDialogBuilder(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
Function(num) setPrice,
|
MobileScannerController scannerController,
|
||||||
MobileScannerController controller,
|
|
||||||
AddViewModel viewModel,
|
AddViewModel viewModel,
|
||||||
Book book,
|
Book book,
|
||||||
) {
|
) {
|
||||||
controller.stop();
|
scannerController.stop();
|
||||||
|
|
||||||
|
// Utility function to pass to downwards widgets
|
||||||
void exitPopup(BuildContext localContext) {
|
void exitPopup(BuildContext localContext) {
|
||||||
Navigator.of(localContext).pop();
|
Navigator.of(localContext).pop();
|
||||||
controller.start();
|
scannerController.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
return showDialog(
|
return showDialog(
|
||||||
|
|
@ -250,7 +276,6 @@ Future<void> _confirmationDialogBuilder(
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
builder: (context) => ConfirmationPopup(
|
builder: (context) => ConfirmationPopup(
|
||||||
exitPopup: exitPopup,
|
exitPopup: exitPopup,
|
||||||
setPrice: setPrice,
|
|
||||||
viewModel: viewModel,
|
viewModel: viewModel,
|
||||||
book: book,
|
book: book,
|
||||||
),
|
),
|
||||||
|
|
@ -264,6 +289,7 @@ Future<void> _formDialogBuilder(
|
||||||
) {
|
) {
|
||||||
controller.stop();
|
controller.stop();
|
||||||
|
|
||||||
|
// Utility function to pass to downwards widgets
|
||||||
void exitPopup(BuildContext localContext) {
|
void exitPopup(BuildContext localContext) {
|
||||||
Navigator.of(localContext).pop();
|
Navigator.of(localContext).pop();
|
||||||
controller.start();
|
controller.start();
|
||||||
|
|
@ -272,7 +298,12 @@ Future<void> _formDialogBuilder(
|
||||||
return showDialog(
|
return showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
builder: (context) => FormPopup(viewModel: viewModel, exitPopup: exitPopup),
|
builder: (context) => FormPopup(
|
||||||
|
viewModel: viewModel,
|
||||||
|
exitPopup: exitPopup,
|
||||||
|
scannerController: controller,
|
||||||
|
scanEan: _scanEan,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -283,7 +314,8 @@ Future<void> _ownerDialogBuilder(
|
||||||
) {
|
) {
|
||||||
controller.stop();
|
controller.stop();
|
||||||
|
|
||||||
void onPressAccept(BuildContext localContext) {
|
// Utility function to pass to downwards widgets
|
||||||
|
void exitPopup(BuildContext localContext) {
|
||||||
Navigator.of(localContext).pop();
|
Navigator.of(localContext).pop();
|
||||||
controller.start();
|
controller.start();
|
||||||
}
|
}
|
||||||
|
|
@ -292,6 +324,6 @@ Future<void> _ownerDialogBuilder(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
OwnerPopup(viewModel: viewModel, onPressAccept: onPressAccept),
|
OwnerPopup(viewModel: viewModel, exitPopup: exitPopup),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,11 @@ class ConfirmationPopup extends StatefulWidget {
|
||||||
const ConfirmationPopup({
|
const ConfirmationPopup({
|
||||||
super.key,
|
super.key,
|
||||||
required this.exitPopup,
|
required this.exitPopup,
|
||||||
required this.setPrice,
|
|
||||||
required this.viewModel,
|
required this.viewModel,
|
||||||
required this.book,
|
required this.book,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Function(BuildContext) exitPopup;
|
final Function(BuildContext) exitPopup;
|
||||||
final Function(num) setPrice;
|
|
||||||
final AddViewModel viewModel;
|
final AddViewModel viewModel;
|
||||||
final Book book;
|
final Book book;
|
||||||
|
|
||||||
|
|
@ -24,9 +22,11 @@ class ConfirmationPopup extends StatefulWidget {
|
||||||
class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
||||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||||
double price = 0;
|
double price = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text("Prix"),
|
title: Text("Prix"),
|
||||||
content: Form(
|
content: Form(
|
||||||
|
|
@ -72,6 +72,7 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
(widget.viewModel.askPrice)
|
(widget.viewModel.askPrice)
|
||||||
? TextFormField(
|
? TextFormField(
|
||||||
|
|
@ -87,15 +88,21 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
return "Indiquez un prix";
|
return "Indiquez un prix";
|
||||||
} else if (num.tryParse(value) == null) {
|
} else if (double.tryParse(
|
||||||
|
value.replaceAll(",", "."),
|
||||||
|
) ==
|
||||||
|
null) {
|
||||||
return "Le prix doit être un nombre";
|
return "Le prix doit être un nombre";
|
||||||
} else if (num.parse(value) < 0) {
|
} else if (double.parse(value.replaceAll(",", ".")) <
|
||||||
|
0) {
|
||||||
return "Le prix doit être positif ou nul";
|
return "Le prix doit être positif ou nul";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
onSaved: (newValue) {
|
onSaved: (newValue) {
|
||||||
price = double.parse(newValue!);
|
price = double.parse(
|
||||||
|
newValue?.replaceAll(",", ".") ?? "0",
|
||||||
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
: SizedBox(),
|
: SizedBox(),
|
||||||
|
|
@ -105,6 +112,7 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
|
child: Text("Annuler"),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
|
|
@ -114,13 +122,15 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
||||||
);
|
);
|
||||||
widget.exitPopup(context);
|
widget.exitPopup(context);
|
||||||
},
|
},
|
||||||
child: Text("Annuler"),
|
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
|
child: Text("Valider"),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (widget.viewModel.askPrice &&
|
if (widget.viewModel.askPrice &&
|
||||||
_formKey.currentState!.validate()) {
|
_formKey.currentState!.validate()) {
|
||||||
_formKey.currentState!.save();
|
_formKey.currentState!.save();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = await widget.viewModel.sendNewBookInstance(
|
var result = await widget.viewModel.sendNewBookInstance(
|
||||||
|
|
@ -136,49 +146,61 @@ class _ConfirmationPopupState extends State<ConfirmationPopup> {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
barrierDismissible: false,
|
||||||
title: Text(
|
builder: (context) =>
|
||||||
"ID : ${widget.viewModel.currentOwner!.firstName[0].toUpperCase()}${widget.viewModel.currentOwner!.lastName[0].toUpperCase()}${(price == 0) ? "PL" : price.toString()}",
|
RegisteredBookPopup(widget: widget, price: price),
|
||||||
),
|
|
||||||
content: Text(
|
|
||||||
(widget.viewModel.currentOwner!.id ==
|
|
||||||
widget.viewModel.ownerOfUser!.id)
|
|
||||||
? "Ce livre appartient à la section. Vous pouvez mettre le code, ou poser une gomette, ..."
|
|
||||||
: "Identifiant propriétaire de ce livre. Pensez à l'écrire pour retrouver lae propriétaire du livre lors de la vente ou du retour !",
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
widget.exitPopup(context);
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(
|
|
||||||
"Enregistré: ${widget.book.title}",
|
|
||||||
),
|
|
||||||
behavior: SnackBarBehavior.floating,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: Text("Ok"),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Error():
|
case Error():
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(content: Text("Erreur : ${result.error}")),
|
||||||
content: Text(
|
|
||||||
"Une erreur est survenue : ${result.error}",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Text("Valider"),
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RegisteredBookPopup extends StatelessWidget {
|
||||||
|
const RegisteredBookPopup({
|
||||||
|
super.key,
|
||||||
|
required this.widget,
|
||||||
|
required this.price,
|
||||||
|
});
|
||||||
|
|
||||||
|
final ConfirmationPopup widget;
|
||||||
|
final double price;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
// This thing is the BookInstance's short ID
|
||||||
|
title: Text(
|
||||||
|
"ID : ${widget.viewModel.currentOwner!.firstName[0].toUpperCase()}${widget.viewModel.currentOwner!.lastName[0].toUpperCase()}${(price == 0) ? "PL" : price.toString()}",
|
||||||
|
),
|
||||||
|
content: Text(
|
||||||
|
(widget.viewModel.currentOwner!.id == widget.viewModel.ownerOfUser!.id)
|
||||||
|
? "Pensez à la gomette ! Ce livre appartient au syndicat."
|
||||||
|
: "Identifiant propriétaire de ce livre. Pensez à l'écrire pour retrouver lae propriétaire du livre lors de la vente ou du retour !",
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: Text("Ok"),
|
||||||
|
onPressed: () {
|
||||||
|
widget.exitPopup(context);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text("Livre enregistré: ${widget.book.title}"),
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
duration: Duration(seconds: 2),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||||
import 'package:seshat/ui/add_page/view_model/add_view_model.dart';
|
import 'package:seshat/ui/add_page/view_model/add_view_model.dart';
|
||||||
|
|
||||||
class FormPopup extends StatelessWidget {
|
class FormPopup extends StatelessWidget {
|
||||||
|
|
@ -6,10 +7,14 @@ class FormPopup extends StatelessWidget {
|
||||||
super.key,
|
super.key,
|
||||||
required this.viewModel,
|
required this.viewModel,
|
||||||
required this.exitPopup,
|
required this.exitPopup,
|
||||||
|
required this.scannerController,
|
||||||
|
required this.scanEan,
|
||||||
});
|
});
|
||||||
|
|
||||||
final AddViewModel viewModel;
|
final AddViewModel viewModel;
|
||||||
final Function(BuildContext) exitPopup;
|
final Function(BuildContext) exitPopup;
|
||||||
|
final MobileScannerController scannerController;
|
||||||
|
final Function scanEan;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
@ -31,6 +36,8 @@ class FormPopup extends StatelessWidget {
|
||||||
return _ManualEANPopup(
|
return _ManualEANPopup(
|
||||||
exitPopup: exitPopup,
|
exitPopup: exitPopup,
|
||||||
viewModel: viewModel,
|
viewModel: viewModel,
|
||||||
|
scannerController: scannerController,
|
||||||
|
scanEan: scanEan,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -51,6 +58,7 @@ class FormPopup extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
clipBehavior: Clip.hardEdge,
|
clipBehavior: Clip.hardEdge,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
|
|
@ -93,11 +101,24 @@ class FormPopup extends StatelessWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ======================
|
||||||
|
* ====< MANUAL EAN >====
|
||||||
|
* ======================
|
||||||
|
*/
|
||||||
|
|
||||||
class _ManualEANPopup extends StatefulWidget {
|
class _ManualEANPopup extends StatefulWidget {
|
||||||
const _ManualEANPopup({required this.exitPopup, required this.viewModel});
|
const _ManualEANPopup({
|
||||||
|
required this.exitPopup,
|
||||||
|
required this.viewModel,
|
||||||
|
required this.scannerController,
|
||||||
|
required this.scanEan,
|
||||||
|
});
|
||||||
|
|
||||||
final Function(BuildContext) exitPopup;
|
final Function(BuildContext) exitPopup;
|
||||||
final AddViewModel viewModel;
|
final AddViewModel viewModel;
|
||||||
|
final MobileScannerController scannerController;
|
||||||
|
final Function scanEan;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_ManualEANPopup> createState() => _ManualEANPopupState();
|
State<_ManualEANPopup> createState() => _ManualEANPopupState();
|
||||||
|
|
@ -106,11 +127,11 @@ class _ManualEANPopup extends StatefulWidget {
|
||||||
class _ManualEANPopupState extends State<_ManualEANPopup> {
|
class _ManualEANPopupState extends State<_ManualEANPopup> {
|
||||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||||
String? ean;
|
String? ean;
|
||||||
num? price;
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text("Recherche par EAN"),
|
title: Text("Entrée manuelle par EAN"),
|
||||||
content: Form(
|
content: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|
@ -128,61 +149,39 @@ class _ManualEANPopupState extends State<_ManualEANPopup> {
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value == null ||
|
if (value == null ||
|
||||||
value.length != 13 ||
|
value.length != 13 ||
|
||||||
int.tryParse(value) == null) {
|
int.tryParse(value) == null ||
|
||||||
|
int.parse(value) < 0) {
|
||||||
return "L'entrée n'est pas un code EAN-13 valide";
|
return "L'entrée n'est pas un code EAN-13 valide";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SizedBox(height: 10),
|
|
||||||
ListenableBuilder(
|
|
||||||
listenable: widget.viewModel,
|
|
||||||
builder: (context, child) {
|
|
||||||
return (widget.viewModel.askPrice)
|
|
||||||
? TextFormField(
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: "Prix",
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
suffixText: "€",
|
|
||||||
),
|
|
||||||
keyboardType: TextInputType.numberWithOptions(
|
|
||||||
decimal: true,
|
|
||||||
),
|
|
||||||
validator: (value) {
|
|
||||||
if (value == null || value.isEmpty) {
|
|
||||||
return "Indiquez un prix";
|
|
||||||
} else if (num.tryParse(value) == null) {
|
|
||||||
return "Le prix doit être un nombre";
|
|
||||||
} else if (num.parse(value) < 0) {
|
|
||||||
return "Le prix doit être positif ou nul";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
onSaved: (newValue) {
|
|
||||||
price = num.parse(newValue!);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: SizedBox();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
|
child: Text("Annuler"),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
widget.exitPopup(context);
|
widget.exitPopup(context);
|
||||||
},
|
},
|
||||||
child: Text("Annuler"),
|
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
|
child: Text("Valider"),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (_formKey.currentState!.validate()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
_formKey.currentState!.save();
|
_formKey.currentState!.save();
|
||||||
widget.exitPopup(context);
|
widget.scanEan(
|
||||||
|
context,
|
||||||
|
widget.viewModel,
|
||||||
|
ean!,
|
||||||
|
widget.scannerController,
|
||||||
|
leaveLastPopup: (context) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Text("Valider"),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ class OwnerPopup extends StatefulWidget {
|
||||||
const OwnerPopup({
|
const OwnerPopup({
|
||||||
super.key,
|
super.key,
|
||||||
required this.viewModel,
|
required this.viewModel,
|
||||||
required this.onPressAccept,
|
required this.exitPopup,
|
||||||
});
|
});
|
||||||
|
|
||||||
final AddViewModel viewModel;
|
final AddViewModel viewModel;
|
||||||
final Function(BuildContext) onPressAccept;
|
final Function(BuildContext) exitPopup;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<OwnerPopup> createState() => _OwnerPopupState();
|
State<OwnerPopup> createState() => _OwnerPopupState();
|
||||||
|
|
@ -166,7 +166,7 @@ class _OwnerPopupState extends State<OwnerPopup> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
widget.onPressAccept(context);
|
widget.exitPopup(context);
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
(!showNewOwner && searchController.text == "")
|
(!showNewOwner && searchController.text == "")
|
||||||
|
|
|
||||||
Reference in a new issue