import 'package:flutter/material.dart'; import 'package:seshat/ui/home_page/view_model/home_view_model.dart'; class CreateConfirmationPopup extends StatefulWidget { const CreateConfirmationPopup({super.key, required this.viewModel}); final HomeViewModel viewModel; @override State createState() => _CreateConfirmationPopupState(); } class _CreateConfirmationPopupState extends State { final GlobalKey _formKey = GlobalKey(); String? name; @override Widget build(BuildContext context) { return AlertDialog( title: Text("Créer une BAL"), content: Column( mainAxisSize: MainAxisSize.min, children: [ Form( key: _formKey, child: Column( mainAxisSize: MainAxisSize.min, children: [ TextFormField( decoration: InputDecoration( labelText: "Nom de la BAL", border: OutlineInputBorder(), ), validator: (value) { if (value == null || value.isEmpty) { return "Veuillez entrer un nom"; } return null; }, onSaved: (newValue) { name = newValue; }, ), ], ), ), ], ), actions: [ TextButton( onPressed: () { Navigator.of(context).pop(); }, child: Text("Annuler"), ), TextButton( onPressed: () async { if (_formKey.currentState!.validate()) { _formKey.currentState!.save(); await widget.viewModel.createBal(name!); } if (context.mounted) { Navigator.of(context).pop(); } }, child: Text("Valider"), ), ], ); } }