change place input + fix endpoint
This commit is contained in:
parent
4b75abe6b6
commit
a5533aa0d3
@ -50,7 +50,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
TextEditingController inputItem = TextEditingController();
|
||||
|
||||
bool showDateFields = false; // State to toggle date fields
|
||||
|
||||
bool showArrow = true;
|
||||
// Fetching events from API
|
||||
static Future<List<Events>> getPosts() async {
|
||||
PermissionStatus status = await Permission.location.status;
|
||||
@ -258,6 +258,9 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
'geometry'], // Include geometry for latitude/longitude
|
||||
})
|
||||
.toList();
|
||||
if (suggestions.isNotEmpty) {
|
||||
showArrow = false;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
throw Exception('Failed to load suggestions');
|
||||
@ -272,7 +275,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
double latitude = prefs.getDouble("city_lat") ?? 0.0;
|
||||
double longitude = prefs.getDouble("city_long") ?? 0.0;
|
||||
String stringParameter = "";
|
||||
String dateParameter = "current_datetime";
|
||||
String endpoint = "events";
|
||||
if ((latitude != 0.0) && (longitude != 0.0)) {
|
||||
// Calculate the boundaries
|
||||
double radiusInKm = 50;
|
||||
@ -283,19 +286,22 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
double maxLat = latitude + latDistance;
|
||||
double minLon = longitude - lonDistance;
|
||||
double maxLon = longitude + lonDistance;
|
||||
endpoint = "events/search";
|
||||
|
||||
stringParameter = "min_lat=$minLat&max_lat=$maxLat"
|
||||
"&min_lon=$minLon&max_lon=$maxLon";
|
||||
}
|
||||
DateTime currentDate = DateTime.now();
|
||||
dateParameter = "¤t_datetime=${currentDate.toString()}";
|
||||
String dateParameter = "current_datetime=${currentDate.toString()}";
|
||||
if (startDatepicker.text.isNotEmpty) {
|
||||
var date = DateTime.parse(formatDate(startDatepicker.text));
|
||||
dateParameter = "&date_event=" + date.toString();
|
||||
dateParameter = "date_event=" + date.toString();
|
||||
endpoint = "events/search";
|
||||
}
|
||||
if (endDatepicker.text.isNotEmpty) {
|
||||
var date = DateTime.parse(formatDate(endDatepicker.text));
|
||||
dateParameter = "&date_event=" + date.toString();
|
||||
dateParameter = "date_event=" + date.toString();
|
||||
endpoint = "events/search";
|
||||
}
|
||||
if ((startDatepicker.text.isNotEmpty) &&
|
||||
(endDatepicker.text.isNotEmpty)) {
|
||||
@ -305,13 +311,20 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
startDate.toString() +
|
||||
"&end_date=" +
|
||||
endDate.toString();
|
||||
endpoint = "events/search";
|
||||
}
|
||||
stringParameter = stringParameter + dateParameter;
|
||||
|
||||
if (inputItem.text.isNotEmpty) {
|
||||
stringParameter = stringParameter + "&item=${inputItem.text}";
|
||||
endpoint = "events/search";
|
||||
}
|
||||
if (stringParameter.isNotEmpty) {
|
||||
stringParameter = "$stringParameter&$dateParameter";
|
||||
} else {
|
||||
stringParameter = dateParameter;
|
||||
}
|
||||
print("stringParameter : ${stringParameter}");
|
||||
var url = Uri.parse("${globals.api}/events/search?${stringParameter}");
|
||||
var url = Uri.parse("${globals.api}/${endpoint}?${stringParameter}");
|
||||
final response = await http.get(url, headers: {
|
||||
"Content-Type": "application/json",
|
||||
HttpHeaders.cookieHeader: "access_token=$accessToken"
|
||||
@ -408,10 +421,9 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
inputGeo.clear(); // Clear the text field
|
||||
geographicalZone = ''; // Reset the geographical zone state
|
||||
suggestions.clear(); // Optionally clear suggestions
|
||||
fetchPostsByLocation();
|
||||
|
||||
/// Clear the filtered posts
|
||||
});
|
||||
fetchPostsByLocation();
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -424,7 +436,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
),
|
||||
if (suggestions.isNotEmpty)
|
||||
Container(
|
||||
height: 200,
|
||||
height: 175,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.blue),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
@ -445,6 +457,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
geographicalZone = suggestions[index]['place_name'];
|
||||
inputGeo.text = geographicalZone;
|
||||
suggestions.clear();
|
||||
showArrow = true;
|
||||
});
|
||||
SharedPreferences prefs =
|
||||
await SharedPreferences.getInstance();
|
||||
@ -506,23 +519,29 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
body: Column(
|
||||
children: [
|
||||
_buildItemZoneSearchField(),
|
||||
if (showDateFields)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
Flexible(child: _buildDateField("start")),
|
||||
Flexible(child: _buildDateField("end"))
|
||||
]),
|
||||
if (showDateFields) _buildGeographicalZoneSearchField(),
|
||||
if (showDateFields) _buildDateField("start"),
|
||||
if (showDateFields) _buildDateField("end"),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
showDateFields = !showDateFields; // Toggle visibility
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
showDateFields
|
||||
? Icons.keyboard_arrow_up
|
||||
: Icons.keyboard_arrow_down,
|
||||
color: Colors.blue,
|
||||
if (showArrow)
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
showDateFields = !showDateFields; // Toggle visibility
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
showDateFields
|
||||
? Icons.keyboard_arrow_up
|
||||
: Icons.keyboard_arrow_down,
|
||||
color: Colors.blue,
|
||||
),
|
||||
tooltip: showDateFields ? 'Show Date Fields' : 'Hide Date Fields',
|
||||
),
|
||||
tooltip: showDateFields ? 'Show Date Fields' : 'Hide Date Fields',
|
||||
),
|
||||
Expanded(
|
||||
child: FutureBuilder<List<Events>>(
|
||||
future: postsFuture,
|
||||
|
Loading…
x
Reference in New Issue
Block a user