search by date work

This commit is contained in:
Valentin CZERYBA 2024-11-23 17:59:52 +01:00
parent d4f8ee2182
commit 431b8d78ad
2 changed files with 12 additions and 7 deletions

View File

@ -131,9 +131,8 @@ class _MyHomePageState extends State<ListItemMenu> {
var url = Uri.parse( var url = Uri.parse(
"${globals.api}/events?current_datetime=${currentDateTime.toString()}"); "${globals.api}/events?current_datetime=${currentDateTime.toString()}");
if (Datepicker.text.isNotEmpty) { if (Datepicker.text.isNotEmpty) {
TimeOfDay time = TimeOfDay.now(); var date = DateTime.parse(formatDate(Datepicker.text));
var date = formatDate(Datepicker.text) + "T" + time.toString(); url = Uri.parse("${globals.api}/events?date_event=${date.toString()}");
url = Uri.parse("${globals.api}/events?date_event=${date}");
} }
final response = await http.get(url, headers: { final response = await http.get(url, headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@ -317,16 +316,17 @@ class _MyHomePageState extends State<ListItemMenu> {
double minLon = longitude - lonDistance; double minLon = longitude - lonDistance;
double maxLon = longitude + lonDistance; double maxLon = longitude + lonDistance;
DateTime currentDate = DateTime.now(); DateTime currentDate = DateTime.now();
print("current_date : ${currentDate}");
var url = Uri.parse("${globals.api}/events/search" var url = Uri.parse("${globals.api}/events/search"
"?min_lat=$minLat&max_lat=$maxLat" "?min_lat=$minLat&max_lat=$maxLat"
"&min_lon=$minLon&max_lon=$maxLon&current_datetime=${currentDate.toString()}"); "&min_lon=$minLon&max_lon=$maxLon&current_datetime=${currentDate.toString()}");
if (Datepicker.text.isNotEmpty) { if (Datepicker.text.isNotEmpty) {
TimeOfDay time = TimeOfDay.now(); var date = DateTime.parse(formatDate(Datepicker.text));
var date = formatDate(Datepicker.text) + "T" + time.toString(); print("date_event ${date.toString()}");
url = Uri.parse("${globals.api}/events/search" url = Uri.parse("${globals.api}/events/search"
"?min_lat=$minLat&max_lat=$maxLat" "?min_lat=$minLat&max_lat=$maxLat"
"&min_lon=$minLon&max_lon=$maxLon&date_event=" + "&min_lon=$minLon&max_lon=$maxLon&date_event=" +
date); date.toString());
} }
final response = await http.get(url, headers: { final response = await http.get(url, headers: {
@ -390,6 +390,11 @@ class _MyHomePageState extends State<ListItemMenu> {
setState(() { setState(() {
Datepicker.text = ''; Datepicker.text = '';
}); });
if (inputGeo.text.isNotEmpty) {
fetchPostsByLocation();
} else {
_fetchInitialData();
}
}, },
), ),
hintText: 'Recherche par date'), hintText: 'Recherche par date'),

View File

@ -95,7 +95,7 @@ class SearchDelegateExample extends SearchDelegate {
String currentDate = DateTime.now().toString(); String currentDate = DateTime.now().toString();
String date = prefs.getString("date_event") ?? ""; String date = prefs.getString("date_event") ?? "";
if (date.isNotEmpty) { if (date.isNotEmpty) {
currentDate = formatDate(date) + "T" + TimeOfDay.now().toString(); currentDate = DateTime.parse(formatDate(date)).toString();
parameter = "date_event"; parameter = "date_event";
} }
var url = Uri.parse( var url = Uri.parse(