feat: add price popup
This commit is contained in:
parent
60265b9735
commit
70146055df
2 changed files with 104 additions and 5 deletions
|
|
@ -4,6 +4,7 @@ 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/widgets/form_popup.dart';
|
||||
import 'package:seshat/ui/add_page/widgets/owner_popup.dart';
|
||||
import 'package:seshat/ui/add_page/widgets/price_popup.dart';
|
||||
import 'package:seshat/ui/core/ui/navigation_bar.dart';
|
||||
|
||||
class AddPage extends StatefulWidget {
|
||||
|
|
@ -16,6 +17,7 @@ class AddPage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _AddPageState extends State<AddPage> {
|
||||
num? price;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final MobileScannerController controller = MobileScannerController(
|
||||
|
|
@ -33,8 +35,28 @@ class _AddPageState extends State<AddPage> {
|
|||
ColoredBox(color: Colors.black),
|
||||
MobileScanner(
|
||||
controller: controller,
|
||||
onDetect: (barcodes) {
|
||||
onBarcodeScan(barcodes, controller);
|
||||
onDetect: (barcodes) async {
|
||||
void setPrice(num newPrice) {
|
||||
setState(() {
|
||||
price = newPrice;
|
||||
});
|
||||
}
|
||||
|
||||
if (widget.viewModel.askPrice) {
|
||||
await _priceDialogBuilder(context, setPrice, controller);
|
||||
} else {
|
||||
setPrice(0);
|
||||
}
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
"Envoyé : ${barcodes.barcodes.first.rawValue} pour $price€",
|
||||
),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
debugPrint(price.toString());
|
||||
},
|
||||
),
|
||||
SafeArea(
|
||||
|
|
@ -106,11 +128,23 @@ class _AddPageState extends State<AddPage> {
|
|||
}
|
||||
}
|
||||
|
||||
void onBarcodeScan(
|
||||
BarcodeCapture barcodes,
|
||||
Future<void> _priceDialogBuilder(
|
||||
BuildContext context,
|
||||
Function(num) setPrice,
|
||||
MobileScannerController controller,
|
||||
) {
|
||||
return;
|
||||
controller.stop();
|
||||
|
||||
void exitPopup(BuildContext localContext) {
|
||||
Navigator.of(localContext).pop();
|
||||
controller.start();
|
||||
}
|
||||
|
||||
return showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => PricePopup(exitPopup: exitPopup, setPrice: setPrice),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _formDialogBuilder(
|
||||
|
|
|
|||
Reference in a new issue