refactor code
This commit is contained in:
parent
56ae77137c
commit
b7fe1da681
@ -281,62 +281,58 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Uri> getUrlForEvents() async {
|
Future<Uri> getUrlForEvents() async {
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
double latitude = prefs.getDouble("city_lat") ?? 0.0;
|
final latitude = prefs.getDouble("city_lat") ?? 0.0;
|
||||||
double longitude = prefs.getDouble("city_long") ?? 0.0;
|
final longitude = prefs.getDouble("city_long") ?? 0.0;
|
||||||
String stringParameter = "";
|
|
||||||
|
final radiusInKm = 50;
|
||||||
String endpoint = "events";
|
String endpoint = "events";
|
||||||
if ((latitude != 0.0) && (longitude != 0.0)) {
|
String queryParameters = "";
|
||||||
// Calculate the boundaries
|
|
||||||
double radiusInKm = 50;
|
|
||||||
double latDistance = radiusInKm / 111.0;
|
|
||||||
double lonDistance = radiusInKm / (111.0 * cos(latitude * pi / 180));
|
|
||||||
|
|
||||||
double minLat = latitude - latDistance;
|
if (latitude != 0.0 && longitude != 0.0) {
|
||||||
double maxLat = latitude + latDistance;
|
final latDistance = radiusInKm / 111.0;
|
||||||
double minLon = longitude - lonDistance;
|
final lonDistance = radiusInKm / (111.0 * cos(latitude * pi / 180));
|
||||||
double maxLon = longitude + lonDistance;
|
|
||||||
endpoint = "events/search";
|
final minLat = latitude - latDistance;
|
||||||
|
final maxLat = latitude + latDistance;
|
||||||
|
final minLon = longitude - lonDistance;
|
||||||
|
final maxLon = longitude + lonDistance;
|
||||||
|
|
||||||
stringParameter = "min_lat=$minLat&max_lat=$maxLat"
|
|
||||||
"&min_lon=$minLon&max_lon=$maxLon";
|
|
||||||
}
|
|
||||||
DateTime currentDate = DateTime.now();
|
|
||||||
String dateParameter = "current_datetime=${currentDate.toString()}";
|
|
||||||
if (startDatepicker.text.isNotEmpty) {
|
|
||||||
var date = DateTime.parse(formatDate(startDatepicker.text));
|
|
||||||
dateParameter = "date_event=" + date.toString();
|
|
||||||
endpoint = "events/search";
|
endpoint = "events/search";
|
||||||
|
queryParameters =
|
||||||
|
"min_lat=$minLat&max_lat=$maxLat&min_lon=$minLon&max_lon=$maxLon";
|
||||||
}
|
}
|
||||||
if (endDatepicker.text.isNotEmpty) {
|
|
||||||
var date = DateTime.parse(formatDate(endDatepicker.text));
|
final currentDate = DateTime.now();
|
||||||
dateParameter = "date_event=" + date.toString();
|
String dateParameter = "current_datetime=${currentDate.toIso8601String()}";
|
||||||
endpoint = "events/search";
|
|
||||||
}
|
if (startDatepicker.text.isNotEmpty || endDatepicker.text.isNotEmpty) {
|
||||||
if ((startDatepicker.text.isNotEmpty) && (endDatepicker.text.isNotEmpty)) {
|
|
||||||
var startDate = DateTime.parse(formatDate(startDatepicker.text));
|
|
||||||
var endDate = DateTime.parse(formatDate(endDatepicker.text));
|
|
||||||
dateParameter = "&start_date=" +
|
|
||||||
startDate.toString() +
|
|
||||||
"&end_date=" +
|
|
||||||
endDate.toString();
|
|
||||||
endpoint = "events/search";
|
endpoint = "events/search";
|
||||||
|
if (startDatepicker.text.isNotEmpty) {
|
||||||
|
final startDate = DateTime.parse(formatDate(startDatepicker.text));
|
||||||
|
dateParameter = "start_date=${startDate.toIso8601String()}";
|
||||||
|
}
|
||||||
|
if (endDatepicker.text.isNotEmpty) {
|
||||||
|
final endDate = DateTime.parse(formatDate(endDatepicker.text));
|
||||||
|
dateParameter += "&end_date=${endDate.toIso8601String()}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputItem.text.isNotEmpty) {
|
if (inputItem.text.isNotEmpty) {
|
||||||
stringParameter = stringParameter + "&item=${inputItem.text}";
|
queryParameters += "&item=${inputItem.text}";
|
||||||
endpoint = "events/search";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputTags.text.isNotEmpty) {
|
if (inputTags.text.isNotEmpty) {
|
||||||
stringParameter = stringParameter + "&tags=${inputTags.text}";
|
queryParameters += "&tags=${inputTags.text}";
|
||||||
endpoint = "events/search";
|
|
||||||
}
|
}
|
||||||
if (stringParameter.isNotEmpty) {
|
|
||||||
stringParameter = "$stringParameter&$dateParameter";
|
if (queryParameters.isNotEmpty) {
|
||||||
|
queryParameters = "$queryParameters&$dateParameter";
|
||||||
} else {
|
} else {
|
||||||
stringParameter = dateParameter;
|
queryParameters = dateParameter;
|
||||||
}
|
}
|
||||||
return Uri.parse("${globals.api}/${endpoint}?${stringParameter}");
|
|
||||||
|
return Uri.parse("${globals.api}/$endpoint?$queryParameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> searchSuggestionsByItem(String input) async {
|
Future<void> searchSuggestionsByItem(String input) async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user