From 431b8d78ada13647018fb288a3cb002868161d69 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 23 Nov 2024 17:59:52 +0100 Subject: [PATCH] search by date work --- covas_mobile/lib/pages/ListItemMenu.dart | 17 +++++++++++------ covas_mobile/lib/pages/SearchDelegate.dart | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/covas_mobile/lib/pages/ListItemMenu.dart b/covas_mobile/lib/pages/ListItemMenu.dart index b6a92ef..3afaecb 100644 --- a/covas_mobile/lib/pages/ListItemMenu.dart +++ b/covas_mobile/lib/pages/ListItemMenu.dart @@ -131,9 +131,8 @@ class _MyHomePageState extends State { var url = Uri.parse( "${globals.api}/events?current_datetime=${currentDateTime.toString()}"); if (Datepicker.text.isNotEmpty) { - TimeOfDay time = TimeOfDay.now(); - var date = formatDate(Datepicker.text) + "T" + time.toString(); - url = Uri.parse("${globals.api}/events?date_event=${date}"); + var date = DateTime.parse(formatDate(Datepicker.text)); + url = Uri.parse("${globals.api}/events?date_event=${date.toString()}"); } final response = await http.get(url, headers: { "Content-Type": "application/json", @@ -317,16 +316,17 @@ class _MyHomePageState extends State { double minLon = longitude - lonDistance; double maxLon = longitude + lonDistance; DateTime currentDate = DateTime.now(); + print("current_date : ${currentDate}"); var url = Uri.parse("${globals.api}/events/search" "?min_lat=$minLat&max_lat=$maxLat" "&min_lon=$minLon&max_lon=$maxLon¤t_datetime=${currentDate.toString()}"); if (Datepicker.text.isNotEmpty) { - TimeOfDay time = TimeOfDay.now(); - var date = formatDate(Datepicker.text) + "T" + time.toString(); + var date = DateTime.parse(formatDate(Datepicker.text)); + print("date_event ${date.toString()}"); url = Uri.parse("${globals.api}/events/search" "?min_lat=$minLat&max_lat=$maxLat" "&min_lon=$minLon&max_lon=$maxLon&date_event=" + - date); + date.toString()); } final response = await http.get(url, headers: { @@ -390,6 +390,11 @@ class _MyHomePageState extends State { setState(() { Datepicker.text = ''; }); + if (inputGeo.text.isNotEmpty) { + fetchPostsByLocation(); + } else { + _fetchInitialData(); + } }, ), hintText: 'Recherche par date'), diff --git a/covas_mobile/lib/pages/SearchDelegate.dart b/covas_mobile/lib/pages/SearchDelegate.dart index 40c8f88..b996837 100644 --- a/covas_mobile/lib/pages/SearchDelegate.dart +++ b/covas_mobile/lib/pages/SearchDelegate.dart @@ -95,7 +95,7 @@ class SearchDelegateExample extends SearchDelegate { String currentDate = DateTime.now().toString(); String date = prefs.getString("date_event") ?? ""; if (date.isNotEmpty) { - currentDate = formatDate(date) + "T" + TimeOfDay.now().toString(); + currentDate = DateTime.parse(formatDate(date)).toString(); parameter = "date_event"; } var url = Uri.parse(