Compare commits
No commits in common. "f693ffa6b86b6e7925f93b23168262cc2e4fa384" and "cdae84090fab62cb1cf1265b8a53015680ba38ec" have entirely different histories.
f693ffa6b8
...
cdae84090f
@ -1,4 +1,3 @@
|
||||
import 'package:covas_mobile/classes/alert.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart'; // Import dotenv
|
||||
@ -52,37 +51,21 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
// Fetching events from API
|
||||
static Future<List<Events>> getPosts() async {
|
||||
PermissionStatus status = await Permission.location.status;
|
||||
final List<Events> body = [];
|
||||
|
||||
var url = Uri.parse("${globals.api}/events");
|
||||
if (status.isGranted) {
|
||||
print("Location permission granted");
|
||||
|
||||
// Get the current position with high accuracy
|
||||
|
||||
const LocationSettings locationSettings = LocationSettings(
|
||||
accuracy: LocationAccuracy.medium,
|
||||
timeLimit: Duration(seconds: 5),
|
||||
LocationSettings locationSettings = LocationSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
distanceFilter:
|
||||
10, // Optional: Minimum distance (in meters) to trigger location update
|
||||
);
|
||||
|
||||
Position position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: locationSettings,
|
||||
);
|
||||
Position? position;
|
||||
try {
|
||||
position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: locationSettings);
|
||||
} on LocationServiceDisabledException {
|
||||
// Handle location services disabled
|
||||
print('Location services are disabled.');
|
||||
position = await Geolocator.getLastKnownPosition();
|
||||
if (position == null) {
|
||||
print('No last known position available.');
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle other errors
|
||||
print('Failed to get location: $e');
|
||||
position = await Geolocator.getLastKnownPosition();
|
||||
if (position == null) {
|
||||
print('No last known position available.');
|
||||
}
|
||||
}
|
||||
if (position != null) {
|
||||
// Calculate the boundaries
|
||||
double radiusInKm = 50;
|
||||
double latDistance = radiusInKm / 111.0;
|
||||
@ -100,7 +83,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
}
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
var accessToken = prefs.getString("access_token") ?? "";
|
||||
|
||||
final List<Events> body = [];
|
||||
if (accessToken.isNotEmpty) {
|
||||
final response = await http.get(url, headers: {
|
||||
"Content-Type": "application/json",
|
||||
@ -109,7 +92,6 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
final List body = json.decode(utf8.decode(response.bodyBytes));
|
||||
return body.map((e) => Events.fromJson(e)).toList();
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
@ -137,6 +119,8 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
super.initState();
|
||||
// Initialize data fetch when the page loads
|
||||
_getCurrentLocation();
|
||||
|
||||
Datepicker.text = DateFormat("dd-MM-yyyy").format(new DateTime.now());
|
||||
}
|
||||
|
||||
// Get the device's current location
|
||||
@ -147,32 +131,19 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
print("Location permission granted");
|
||||
|
||||
// Get the current position with high accuracy
|
||||
const LocationSettings locationSettings = LocationSettings(
|
||||
accuracy: LocationAccuracy.medium, timeLimit: Duration(seconds: 5));
|
||||
Position? position;
|
||||
try {
|
||||
position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: locationSettings);
|
||||
} on LocationServiceDisabledException {
|
||||
// Handle location services disabled
|
||||
print('Location services are disabled.');
|
||||
position = await Geolocator.getLastKnownPosition();
|
||||
if (position == null) {
|
||||
print('No last known position available.');
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle other errors
|
||||
print('Failed to get location: $e');
|
||||
position = await Geolocator.getLastKnownPosition();
|
||||
if (position == null) {
|
||||
print('No last known position available.');
|
||||
}
|
||||
}
|
||||
LocationSettings locationSettings = LocationSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
distanceFilter:
|
||||
10, // Optional: Minimum distance (in meters) to trigger location update
|
||||
);
|
||||
|
||||
Position position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: locationSettings,
|
||||
);
|
||||
|
||||
// Reverse geocode: Get city and country from latitude and longitude using Mapbox Search API
|
||||
if (position != null) {
|
||||
_getCityAndCountry(position!.latitude, position!.longitude);
|
||||
}
|
||||
final place =
|
||||
await _getCityAndCountry(position.latitude, position.longitude);
|
||||
}
|
||||
}
|
||||
|
||||
@ -332,7 +303,10 @@ class _MyHomePageState extends State<ListItemMenu> {
|
||||
DateTime dateEvent = DateTime.now();
|
||||
|
||||
DateTime? pickedDate = await showDatePicker(
|
||||
context: context, firstDate: dateEvent, lastDate: DateTime(2104));
|
||||
context: context,
|
||||
firstDate: dateEvent,
|
||||
initialDate: dateEvent,
|
||||
lastDate: DateTime(2104));
|
||||
if (pickedDate == null) return;
|
||||
Datepicker.text = DateFormat("dd-MM-yyyy").format(pickedDate);
|
||||
}
|
||||
|
@ -141,33 +141,19 @@ class _MapboxPagesState extends State<MapboxPages> with ShowErrorDialog {
|
||||
"Location permissions are permanently denied. Enable them in settings.");
|
||||
return;
|
||||
}
|
||||
const LocationSettings locationSettings = LocationSettings(
|
||||
accuracy: LocationAccuracy.medium, timeLimit: Duration(seconds: 5));
|
||||
Position? position;
|
||||
try {
|
||||
position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: locationSettings);
|
||||
} on LocationServiceDisabledException {
|
||||
// Handle location services disabled
|
||||
print('Location services are disabled.');
|
||||
position = await Geolocator.getLastKnownPosition();
|
||||
if (position == null) {
|
||||
print('No last known position available.');
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle other errors
|
||||
print('Failed to get location: $e');
|
||||
position = await Geolocator.getLastKnownPosition();
|
||||
if (position == null) {
|
||||
print('No last known position available.');
|
||||
}
|
||||
}
|
||||
if (position != null) {
|
||||
LocationSettings locationSettings = LocationSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
distanceFilter:
|
||||
10, // Optional: Minimum distance (in meters) to trigger location update
|
||||
);
|
||||
|
||||
Position position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: locationSettings,
|
||||
);
|
||||
setState(() {
|
||||
userPosition = LatLng(position!.latitude, position!.longitude);
|
||||
userPosition = LatLng(position.latitude, position.longitude);
|
||||
isUserPositionInitialized = true;
|
||||
});
|
||||
}
|
||||
_initToken();
|
||||
_getEventInfo();
|
||||
} catch (e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user