This repository has been archived on 2025-08-25. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Seshat/lib/ui/add_page/widgets/price_popup.dart
2025-08-05 13:03:45 +02:00

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"),
),
],
);
}
}