feat: add price popup
This commit is contained in:
parent
60265b9735
commit
70146055df
2 changed files with 104 additions and 5 deletions
65
lib/ui/add_page/widgets/price_popup.dart
Normal file
65
lib/ui/add_page/widgets/price_popup.dart
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class PricePopup extends StatefulWidget {
|
||||
const PricePopup({
|
||||
super.key,
|
||||
required this.exitPopup,
|
||||
required this.setPrice,
|
||||
});
|
||||
|
||||
final Function(BuildContext) exitPopup;
|
||||
final Function(num) setPrice;
|
||||
|
||||
@override
|
||||
State<PricePopup> createState() => _PricePopupState();
|
||||
}
|
||||
|
||||
class _PricePopupState extends State<PricePopup> {
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
num? price;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text("Prix"),
|
||||
content: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Prix",
|
||||
border: OutlineInputBorder(),
|
||||
suffixText: "€",
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Indiquez un prix";
|
||||
} else if (num.tryParse(value) == null) {
|
||||
return "Le prix doit être un nombre";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: (newValue) {
|
||||
price = num.parse(newValue!);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
widget.setPrice(price!);
|
||||
widget.exitPopup(context);
|
||||
}
|
||||
},
|
||||
child: Text("Valider"),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in a new issue