feat: start of pending screen

This commit is contained in:
alzalia1 2025-08-14 00:27:39 +02:00
parent 019a21f00e
commit ee9c4c3801
12 changed files with 425 additions and 67 deletions

View file

@ -1,4 +1,6 @@
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 {
@ -14,8 +16,40 @@ class CreateConfirmationPopup extends StatefulWidget {
class _CreateConfirmationPopupState extends State<CreateConfirmationPopup> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
String? name;
DateTime? start;
Future<void> _selectStart() async {
final DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: start ?? DateTime.now(),
firstDate: DateTime.now(),
lastDate: DateTime(DateTime.now().year + 2),
locale: Locale("fr"),
);
setState(() {
start = pickedDate;
});
}
DateTime? end;
Future<void> _selectEnd() async {
final DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: end ?? DateTime.now(),
firstDate: DateTime.now(),
lastDate: DateTime(DateTime.now().year + 2),
locale: Locale("fr"),
);
setState(() {
end = pickedDate;
});
}
@override
Widget build(BuildContext context) {
initializeDateFormatting();
var format = DateFormat("dd MMM yyyy", "fr");
return AlertDialog(
title: Text("Créer une BAL"),
content: Column(
@ -41,6 +75,29 @@ class _CreateConfirmationPopupState extends State<CreateConfirmationPopup> {
name = newValue;
},
),
Row(
children: [
Text("Date de début : "),
TextButton(
onPressed: () {
_selectStart();
},
child: Text(format.format(start ?? DateTime.now())),
),
],
),
Row(
children: [
Text("Date de fin : "),
TextButton(
onPressed: () {
_selectEnd();
},
child: Text(format.format(end ?? DateTime.now())),
),
],
),
Text("Note: Les dates sont à titre purement indicatif."),
],
),
),
@ -55,12 +112,23 @@ class _CreateConfirmationPopupState extends State<CreateConfirmationPopup> {
),
TextButton(
onPressed: () async {
if (_formKey.currentState!.validate()) {
if (_formKey.currentState!.validate() &&
start != null &&
end != null) {
_formKey.currentState!.save();
await widget.viewModel.createBal(name!);
}
if (context.mounted) {
Navigator.of(context).pop();
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"),