65 lines
1.7 KiB
Dart
65 lines
1.7 KiB
Dart
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"),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|