passing parameter
This commit is contained in:
parent
c6a0c2f4f1
commit
a0ece6f973
@ -172,9 +172,6 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
// Reverse geocode: Get city and country from latitude and longitude using Mapbox Search API
|
||||
if (position != null) {
|
||||
_getCityAndCountry(position!.latitude, position!.longitude);
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
prefs.setDouble("city_lat", position!.latitude);
|
||||
prefs.setDouble("city_long", position!.longitude);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -206,7 +203,10 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
String country = _getCountryFromFeatures(features);
|
||||
print("city : ${city} ${country}");
|
||||
if (city.isNotEmpty && country.isNotEmpty) {
|
||||
fetchPostsByLocation(latitude, longitude);
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
prefs.setDouble("city_lat", latitude);
|
||||
prefs.setDouble("city_long", longitude);
|
||||
fetchPostsByLocation();
|
||||
setState(() {
|
||||
inputGeo.text = "${city}, ${country}";
|
||||
});
|
||||
@ -286,11 +286,14 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchPostsByLocation(double latitude, double longitude) async {
|
||||
Future<void> fetchPostsByLocation() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
var accessToken = prefs.getString("access_token") ?? "";
|
||||
|
||||
if (accessToken.isNotEmpty) {
|
||||
double latitude = prefs.getDouble("city_lat") ?? 0.0;
|
||||
double longitude = prefs.getDouble("city_long") ?? 0.0;
|
||||
|
||||
// Calculate the boundaries
|
||||
double radiusInKm = 50;
|
||||
double latDistance = radiusInKm / 111.0;
|
||||
@ -418,12 +421,11 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
inputGeo.text = geographicalZone;
|
||||
suggestions.clear();
|
||||
});
|
||||
|
||||
await fetchPostsByLocation(latitude, longitude);
|
||||
SharedPreferences prefs =
|
||||
await SharedPreferences.getInstance();
|
||||
prefs.setDouble("city_lat", latitude);
|
||||
prefs.setDouble("city_long", longitude);
|
||||
await fetchPostsByLocation();
|
||||
},
|
||||
);
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user