feat: start of pending screen
This commit is contained in:
parent
019a21f00e
commit
ee9c4c3801
12 changed files with 425 additions and 67 deletions
|
|
@ -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"),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:seshat/domain/models/bal.dart';
|
||||
import 'package:seshat/ui/core/ui/navigation_bar.dart';
|
||||
import 'package:seshat/ui/home_page/view_model/home_view_model.dart';
|
||||
|
|
@ -18,6 +20,8 @@ class HomePage extends StatefulWidget {
|
|||
class _HomePageState extends State<HomePage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
initializeDateFormatting();
|
||||
var format = DateFormat("dd MMM yyyy", "fr");
|
||||
return Scaffold(
|
||||
bottomNavigationBar: AppNavigationBar(startIndex: 0),
|
||||
appBar: AppBar(
|
||||
|
|
@ -55,30 +59,24 @@ class _HomePageState extends State<HomePage> {
|
|||
title: Text(bal.name),
|
||||
subtitle: switch (bal.state) {
|
||||
BalState.pending => Text(
|
||||
"À venir · Débute le ${bal.startTime.toString()}",
|
||||
"À venir · Débute le ${format.format(bal.startTime)}",
|
||||
),
|
||||
BalState.ongoing => Text("En cours"),
|
||||
BalState.ended => Text("Terminée"),
|
||||
},
|
||||
trailing: switch (bal.state) {
|
||||
BalState.pending => IconButton(
|
||||
onPressed: () {
|
||||
_moveToBal(context, bal.id);
|
||||
},
|
||||
icon: Icon(Icons.edit),
|
||||
),
|
||||
BalState.ongoing => IconButton(
|
||||
onPressed: () {
|
||||
_moveToBal(context, bal.id);
|
||||
},
|
||||
icon: Icon(Icons.arrow_forward),
|
||||
),
|
||||
BalState.ended => IconButton(
|
||||
onPressed: () {
|
||||
_moveToBal(context, bal.id);
|
||||
},
|
||||
icon: Icon(Icons.analytics),
|
||||
),
|
||||
_ => IconButton(
|
||||
onPressed: () {
|
||||
_moveToBal(context, bal.id);
|
||||
},
|
||||
icon: Icon(Icons.arrow_forward),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
|
|
@ -113,6 +111,7 @@ class _HomePageState extends State<HomePage> {
|
|||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) {
|
||||
return CreateConfirmationPopup(
|
||||
viewModel: widget.viewModel,
|
||||
|
|
|
|||
Reference in a new issue