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 createState() => _PricePopupState(); } class _PricePopupState extends State { final GlobalKey _formKey = GlobalKey(); 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"), ), ], ); } }