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/home_page/widgets/create_confirmation_popup.dart
2025-08-11 22:41:15 +02:00

71 lines
2 KiB
Dart

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