fix: switched to more user friendly datetimerange
This commit is contained in:
parent
d16d1e2778
commit
6ed99248b3
2 changed files with 24 additions and 69 deletions
|
|
@ -61,32 +61,21 @@ class _EditPopup extends State<EditPopup> {
|
|||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
String? name;
|
||||
DateTime? start;
|
||||
Future<void> _selectStart() async {
|
||||
final DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: start ?? widget.viewModel.bal!.startTime,
|
||||
firstDate: DateTime.now(),
|
||||
lastDate: DateTime(DateTime.now().year + 2),
|
||||
locale: Locale("fr", "FR"),
|
||||
);
|
||||
|
||||
setState(() {
|
||||
start = pickedDate;
|
||||
});
|
||||
}
|
||||
|
||||
DateTime? end;
|
||||
Future<void> _selectEnd() async {
|
||||
final DateTime? pickedDate = await showDatePicker(
|
||||
Future<void> _selectRange() async {
|
||||
final DateTimeRange? pickedDate = await showDateRangePicker(
|
||||
context: context,
|
||||
initialDate: end ?? widget.viewModel.bal!.endTime,
|
||||
firstDate: DateTime.now(),
|
||||
firstDate: DateTime(DateTime.now().year - 1),
|
||||
lastDate: DateTime(DateTime.now().year + 2),
|
||||
locale: Locale("fr", "FR"),
|
||||
initialDateRange: DateTimeRange(
|
||||
start: start ?? widget.viewModel.bal!.startTime,
|
||||
end: end ?? widget.viewModel.bal!.endTime,
|
||||
),
|
||||
);
|
||||
|
||||
setState(() {
|
||||
end = pickedDate;
|
||||
start = pickedDate?.start;
|
||||
end = pickedDate?.end;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -125,24 +114,10 @@ class _EditPopup extends State<EditPopup> {
|
|||
Text("Date de début : "),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
_selectStart();
|
||||
_selectRange();
|
||||
},
|
||||
child: Text(
|
||||
format.format(start ?? widget.viewModel.bal!.startTime),
|
||||
locale: Locale("fr"),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text("Date de fin : "),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
_selectEnd();
|
||||
},
|
||||
child: Text(
|
||||
format.format(end ?? widget.viewModel.bal!.endTime),
|
||||
"Du ${format.format(start ?? DateTime.now())}\nau ${format.format(end ?? DateTime.now().add(Duration(days: 1)))}",
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -17,32 +17,21 @@ 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(
|
||||
Future<void> _selectRange() async {
|
||||
final DateTimeRange? pickedDate = await showDateRangePicker(
|
||||
context: context,
|
||||
initialDate: end ?? DateTime.now(),
|
||||
firstDate: DateTime.now(),
|
||||
firstDate: DateTime(DateTime.now().year - 1),
|
||||
lastDate: DateTime(DateTime.now().year + 2),
|
||||
locale: Locale("fr"),
|
||||
initialDateRange: DateTimeRange(
|
||||
start: start ?? DateTime.now(),
|
||||
end: end ?? DateTime.now().add(Duration(days: 1)),
|
||||
),
|
||||
);
|
||||
|
||||
setState(() {
|
||||
end = pickedDate;
|
||||
start = pickedDate?.start;
|
||||
end = pickedDate?.end;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -80,20 +69,11 @@ class _CreateConfirmationPopupState extends State<CreateConfirmationPopup> {
|
|||
Text("Date de début : "),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
_selectStart();
|
||||
_selectRange();
|
||||
},
|
||||
child: Text(format.format(start ?? DateTime.now())),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text("Date de fin : "),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
_selectEnd();
|
||||
},
|
||||
child: Text(format.format(end ?? DateTime.now())),
|
||||
child: Text(
|
||||
"Du ${format.format(start ?? DateTime.now())}\nau ${format.format(end ?? DateTime.now().add(Duration(days: 1)))}",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
|||
Reference in a new issue