fix: some error managment and a whole feature missing

This commit is contained in:
Alzalia 2025-08-23 15:52:51 +02:00
parent dad000a1b9
commit 6bcc3a7e88
5 changed files with 192 additions and 140 deletions

View file

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:seshat/ui/add_page/view_model/add_view_model.dart';
class FormPopup extends StatelessWidget {
@ -6,10 +7,14 @@ class FormPopup extends StatelessWidget {
super.key,
required this.viewModel,
required this.exitPopup,
required this.scannerController,
required this.scanEan,
});
final AddViewModel viewModel;
final Function(BuildContext) exitPopup;
final MobileScannerController scannerController;
final Function scanEan;
@override
Widget build(BuildContext context) {
@ -31,6 +36,8 @@ class FormPopup extends StatelessWidget {
return _ManualEANPopup(
exitPopup: exitPopup,
viewModel: viewModel,
scannerController: scannerController,
scanEan: scanEan,
);
},
);
@ -51,6 +58,7 @@ class FormPopup extends StatelessWidget {
),
),
),
Card(
clipBehavior: Clip.hardEdge,
child: InkWell(
@ -93,11 +101,24 @@ class FormPopup extends StatelessWidget {
}
}
/*
* ======================
* ====< MANUAL EAN >====
* ======================
*/
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 AddViewModel viewModel;
final MobileScannerController scannerController;
final Function scanEan;
@override
State<_ManualEANPopup> createState() => _ManualEANPopupState();
@ -106,11 +127,11 @@ class _ManualEANPopup extends StatefulWidget {
class _ManualEANPopupState extends State<_ManualEANPopup> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
String? ean;
num? price;
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text("Recherche par EAN"),
title: Text("Entrée manuelle par EAN"),
content: Form(
key: _formKey,
child: Column(
@ -128,61 +149,39 @@ class _ManualEANPopupState extends State<_ManualEANPopup> {
validator: (value) {
if (value == null ||
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 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: [
TextButton(
child: Text("Annuler"),
onPressed: () {
widget.exitPopup(context);
},
child: Text("Annuler"),
),
TextButton(
child: Text("Valider"),
onPressed: () {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
widget.exitPopup(context);
widget.scanEan(
context,
widget.viewModel,
ean!,
widget.scannerController,
leaveLastPopup: (context) {
Navigator.of(context).pop();
},
);
}
},
child: Text("Valider"),
),
],
);