diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index 76a5fc3..b09ca67 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -87,38 +87,41 @@ class DisplayPictureScreenState extends State Future searchEvents(String json, String imagePath) async { print(json.replaceAll("'''json", '').replaceAll("'''", "")); SharedPreferences prefs = await SharedPreferences.getInstance(); + try { + Map jsonData = + jsonDecode(json.replaceAll("```json", '').replaceAll("```", "")); + print("json : ${jsonData}"); + var name = jsonData["name"]; + print("name : ${name}"); + var place = jsonData["place"]; + var accessToken = prefs.getString("access_token") ?? ""; - Map jsonData = - jsonDecode(json.replaceAll("```json", '').replaceAll("```", "")); - print("json : ${jsonData}"); - var name = jsonData["name"]; - print("name : ${name}"); - var place = jsonData["place"]; - var accessToken = prefs.getString("access_token") ?? ""; + if (accessToken.isNotEmpty) { + var urlGet = Uri.parse("${globals.api}/events?name=${name}"); - if (accessToken.isNotEmpty) { - var urlGet = Uri.parse("${globals.api}/events?name=${name}"); - - var responseGet = await http.get(urlGet, - headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'}); - if (responseGet.statusCode == 200) { - var events = jsonDecode(utf8.decode(responseGet.bodyBytes)); - print("reponse http : ${events.length}"); - if (events.length == 0) { - Navigator.push( - context, - MaterialPageRoute( - builder: (_) => UpdateeventImage( - events: jsonData, imagePath: imagePath))); - } else { - Navigator.push( - context, - MaterialPageRoute( - builder: (_) => ItemMenu(title: events[0]["id"]))); + var responseGet = await http.get(urlGet, + headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'}); + if (responseGet.statusCode == 200) { + var events = jsonDecode(utf8.decode(responseGet.bodyBytes)); + print("reponse http : ${events.length}"); + if (events.length == 0) { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) => UpdateeventImage( + events: jsonData, imagePath: imagePath))); + } else { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) => ItemMenu(title: events[0]["id"]))); + } } + } else { + showErrorDialog(context, "Erreur de token"); } - } else { - showErrorDialog(context, "Erreur de token"); + } catch (e) { + showErrorDialog(context, "Erreur de format de donnée fourni par l'IA"); } //showDescImageAddDialog(context, message); diff --git a/covas_mobile/lib/pages/UpdateEventImage.dart b/covas_mobile/lib/pages/UpdateEventImage.dart index c3e0bfa..cd32624 100644 --- a/covas_mobile/lib/pages/UpdateEventImage.dart +++ b/covas_mobile/lib/pages/UpdateEventImage.dart @@ -70,10 +70,16 @@ class _UpdateeventImageState extends State 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 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 inputName.text = convertNulltoEmptyString(widget.events["name"]); inputGeo.text = convertNulltoEmptyString(widget.events["place"]); inputDesc.text = convertNulltoEmptyString(widget.events["description"]); - - DateTime pickedStartDate = - DateTime.parse(convertNulltoEmptyString(widget.events["start_date"])); - 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); + 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"])); + endDatepicker.text = DateFormat("dd-MM-yyyy").format(pickedEndDate); + endTimepicker.text = DateFormat("HH-mm").format(pickedEndDate); + } initialTags = List.from(widget.events['tags'] as List); initialOrga = List.from(widget.events['organizers'] as List); }