119 lines
3.5 KiB
Dart
119 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/date_symbol_data_local.dart';
|
|
import 'package:intl/intl.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;
|
|
DateTime? start;
|
|
DateTime? end;
|
|
Future<void> _selectRange() async {
|
|
final DateTimeRange? pickedDate = await showDateRangePicker(
|
|
context: context,
|
|
firstDate: DateTime(DateTime.now().year - 1),
|
|
lastDate: DateTime(DateTime.now().year + 2),
|
|
initialDateRange: DateTimeRange(
|
|
start: start ?? DateTime.now(),
|
|
end: end ?? DateTime.now().add(Duration(days: 1)),
|
|
),
|
|
);
|
|
|
|
setState(() {
|
|
start = pickedDate?.start;
|
|
end = pickedDate?.end;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
initializeDateFormatting();
|
|
var format = DateFormat("dd MMM yyyy", "fr");
|
|
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;
|
|
},
|
|
),
|
|
Row(
|
|
children: [
|
|
Text("Date de début : "),
|
|
TextButton(
|
|
onPressed: () {
|
|
_selectRange();
|
|
},
|
|
child: Text(
|
|
"Du ${format.format(start ?? DateTime.now())}\nau ${format.format(end ?? DateTime.now().add(Duration(days: 1)))}",
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Text("Note: Les dates sont à titre purement indicatif."),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Text("Annuler"),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
if (_formKey.currentState!.validate() &&
|
|
start != null &&
|
|
end != null) {
|
|
_formKey.currentState!.save();
|
|
await widget.viewModel.createBal(name!, start!, end!);
|
|
|
|
if (context.mounted) {
|
|
Navigator.of(context).pop();
|
|
}
|
|
} else {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(
|
|
"Veuillez indiquer une date de début et de fin.",
|
|
),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
child: Text("Valider"),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|