fix datepicker

This commit is contained in:
Valentin CZERYBA 2024-11-08 16:57:07 +01:00
parent 44a0691e31
commit 00a9125eb2
2 changed files with 59 additions and 44 deletions

View File

@ -87,7 +87,7 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
Future<void> searchEvents(String json, String imagePath) async {
print(json.replaceAll("'''json", '').replaceAll("'''", ""));
SharedPreferences prefs = await SharedPreferences.getInstance();
try {
Map<String, dynamic> jsonData =
jsonDecode(json.replaceAll("```json", '').replaceAll("```", ""));
print("json : ${jsonData}");
@ -120,6 +120,9 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
} else {
showErrorDialog(context, "Erreur de token");
}
} catch (e) {
showErrorDialog(context, "Erreur de format de donnée fourni par l'IA");
}
//showDescImageAddDialog(context, message);
}

View File

@ -70,10 +70,16 @@ class _UpdateeventImageState extends State<UpdateeventImage>
if (position == "end") {
date = "end_date";
}
DateTime dateEvent;
if (widget.events[date].toString().isEmpty) {
dateEvent = DateTime.now();
} else {
dateEvent = DateTime.parse(widget.events[date]);
}
DateTime? pickedDate = await showDatePicker(
context: context,
firstDate: DateTime.parse(widget.events[date]),
initialDate: DateTime.parse(widget.events[date]),
firstDate: dateEvent,
initialDate: dateEvent,
lastDate: DateTime(2104));
if (pickedDate == null) return;
if (position == "start") {
@ -90,10 +96,14 @@ class _UpdateeventImageState extends State<UpdateeventImage>
if (position == "end") {
date = "end_date";
}
TimeOfDay? pickedDate = await showTimePicker(
context: context,
initialTime:
TimeOfDay.fromDateTime(DateTime.parse(widget.events[date])));
TimeOfDay timeEvent;
if (widget.events[date].toString().isEmpty) {
timeEvent = TimeOfDay.now();
} else {
timeEvent = TimeOfDay.fromDateTime(DateTime.parse(widget.events[date]));
}
TimeOfDay? pickedDate =
await showTimePicker(context: context, initialTime: timeEvent);
if (pickedDate == null) return;
if (position == "start") {
startTimepicker.text = pickedDate.format(context);
@ -274,16 +284,18 @@ class _UpdateeventImageState extends State<UpdateeventImage>
inputName.text = convertNulltoEmptyString(widget.events["name"]);
inputGeo.text = convertNulltoEmptyString(widget.events["place"]);
inputDesc.text = convertNulltoEmptyString(widget.events["description"]);
if (widget.events["start_date"].toString().isNotEmpty) {
DateTime pickedStartDate =
DateTime.parse(convertNulltoEmptyString(widget.events["start_date"]));
startDatepicker.text = DateFormat("dd-MM-yyyy").format(pickedStartDate);
startTimepicker.text = DateFormat("HH-mm").format(pickedStartDate);
}
if (widget.events["end_date"].toString().isNotEmpty) {
DateTime pickedEndDate =
DateTime.parse(convertNulltoEmptyString(widget.events["end_date"]));
startDatepicker.text = DateFormat("dd-MM-yyyy").format(pickedStartDate);
endDatepicker.text = DateFormat("dd-MM-yyyy").format(pickedEndDate);
startTimepicker.text = DateFormat("HH-mm").format(pickedStartDate);
endTimepicker.text = DateFormat("HH-mm").format(pickedEndDate);
}
initialTags = List<String>.from(widget.events['tags'] as List);
initialOrga = List<String>.from(widget.events['organizers'] as List);
}