add parameter
This commit is contained in:
parent
627eb778ad
commit
d4f8ee2182
@ -112,6 +112,15 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
return body;
|
||||
}
|
||||
|
||||
String formatDate(String date) {
|
||||
var splitedDate = date.split("-");
|
||||
var day = splitedDate[0];
|
||||
var month = splitedDate[1];
|
||||
var year = splitedDate[2];
|
||||
|
||||
return "${year}-${month}-${day}";
|
||||
}
|
||||
|
||||
// Fetching events from API
|
||||
Future<List<Events>> getAllPosts() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
@ -122,8 +131,9 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
var url = Uri.parse(
|
||||
"${globals.api}/events?current_datetime=${currentDateTime.toString()}");
|
||||
if (Datepicker.text.isNotEmpty) {
|
||||
url = Uri.parse(
|
||||
"${globals.api}/events?current_datetime=${currentDateTime.toString()}");
|
||||
TimeOfDay time = TimeOfDay.now();
|
||||
var date = formatDate(Datepicker.text) + "T" + time.toString();
|
||||
url = Uri.parse("${globals.api}/events?date_event=${date}");
|
||||
}
|
||||
final response = await http.get(url, headers: {
|
||||
"Content-Type": "application/json",
|
||||
@ -311,9 +321,12 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
"?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();
|
||||
url = Uri.parse("${globals.api}/events/search"
|
||||
"?min_lat=$minLat&max_lat=$maxLat"
|
||||
"&min_lon=$minLon&max_lon=$maxLon");
|
||||
"?min_lat=$minLat&max_lat=$maxLat"
|
||||
"&min_lon=$minLon&max_lon=$maxLon&date_event=" +
|
||||
date);
|
||||
}
|
||||
|
||||
final response = await http.get(url, headers: {
|
||||
@ -349,6 +362,8 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
context: context, firstDate: dateEvent, lastDate: DateTime(2104));
|
||||
if (pickedDate == null) return;
|
||||
Datepicker.text = DateFormat("dd-MM-yyyy").format(pickedDate);
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString("date_event", Datepicker.text);
|
||||
if (inputGeo.text.isEmpty) {
|
||||
_fetchInitialData();
|
||||
} else {
|
||||
@ -370,8 +385,8 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
onPressed: () async {
|
||||
SharedPreferences prefs =
|
||||
await SharedPreferences.getInstance();
|
||||
prefs.remove("city_lat");
|
||||
prefs.remove("city_long");
|
||||
|
||||
prefs.remove("date_event");
|
||||
setState(() {
|
||||
Datepicker.text = '';
|
||||
});
|
||||
@ -394,7 +409,11 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
border: OutlineInputBorder(),
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
SharedPreferences prefs =
|
||||
await SharedPreferences.getInstance();
|
||||
prefs.remove("city_lat");
|
||||
prefs.remove("city_long");
|
||||
setState(() {
|
||||
inputGeo.clear(); // Clear the text field
|
||||
geographicalZone = ''; // Reset the geographical zone state
|
||||
@ -527,7 +546,6 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
final startDate = DateTime.parse(post.startDate!);
|
||||
final date = DateFormat.yMd().format(startDate);
|
||||
final time = DateFormat.Hm().format(startDate);
|
||||
|
||||
return ListTile(
|
||||
title: Text('${post.name!}'),
|
||||
subtitle: Text('${post.place!}\n${date} ${time}'),
|
||||
|
@ -75,6 +75,15 @@ class SearchDelegateExample extends SearchDelegate {
|
||||
return Container(); // Implement suggestions if needed
|
||||
}
|
||||
|
||||
String formatDate(String date) {
|
||||
var splitedDate = date.split("-");
|
||||
var day = splitedDate[0];
|
||||
var month = splitedDate[1];
|
||||
var year = splitedDate[2];
|
||||
|
||||
return "${year}-${month}-${day}";
|
||||
}
|
||||
|
||||
Future<List<Events>> searchPosts(String query) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
var accessToken = prefs.getString("access_token") ?? "";
|
||||
@ -82,9 +91,15 @@ class SearchDelegateExample extends SearchDelegate {
|
||||
var longitude = prefs.getDouble("city_long") ?? 0.0;
|
||||
final List<Events> body = [];
|
||||
if (accessToken.isNotEmpty) {
|
||||
DateTime currentDate = DateTime.now();
|
||||
String parameter = "current_datetime";
|
||||
String currentDate = DateTime.now().toString();
|
||||
String date = prefs.getString("date_event") ?? "";
|
||||
if (date.isNotEmpty) {
|
||||
currentDate = formatDate(date) + "T" + TimeOfDay.now().toString();
|
||||
parameter = "date_event";
|
||||
}
|
||||
var url = Uri.parse(
|
||||
"${globals.api}/events/search?item=${query}¤t_dateime=${currentDate.toString()}");
|
||||
"${globals.api}/events/search?item=${query}&${parameter}=${currentDate}");
|
||||
if ((latitude != 0.0) && (longitude != 0.0)) {
|
||||
// Now use the latitude and longitude to get events within a 50km radius
|
||||
double radiusInKm = 50;
|
||||
@ -96,7 +111,7 @@ class SearchDelegateExample extends SearchDelegate {
|
||||
double maxLon = longitude + lonDistance;
|
||||
// Construct the search URL with the item query and latitude/longitude bounds
|
||||
url = Uri.parse(
|
||||
"${globals.api}/events/search?item=${query}&min_lat=${minLat}&max_lat=${maxLat}&min_lon=${minLon}&max_lon=${maxLon}¤t_dateime=${currentDate.toString()}");
|
||||
"${globals.api}/events/search?item=${query}&min_lat=${minLat}&max_lat=${maxLat}&min_lon=${minLon}&max_lon=${maxLon}&${parameter}=${currentDate}");
|
||||
}
|
||||
final response = await http.get(url, headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
Loading…
x
Reference in New Issue
Block a user