current date

This commit is contained in:
2024-11-10 18:18:08 +01:00
parent c1e85c255e
commit a427fc5edf
2 changed files with 12 additions and 7 deletions

View File

@@ -50,6 +50,7 @@ class _MyHomePageState extends State<ListItemMenu> {
// Fetching events from API
static Future<List<Events>> getPosts() async {
PermissionStatus status = await Permission.location.status;
var url = Uri.parse("${globals.api}/events");
if (status.isGranted) {
print("Location permission granted");
@@ -74,10 +75,10 @@ class _MyHomePageState extends State<ListItemMenu> {
double maxLat = position.latitude + latDistance;
double minLon = position.longitude - lonDistance;
double maxLon = position.longitude + lonDistance;
DateTime currentDatetime = DateTime.now();
url = Uri.parse("${globals.api}/events/search"
"?min_lat=$minLat&max_lat=$maxLat"
"&min_lon=$minLon&max_lon=$maxLon");
"&min_lon=$minLon&max_lon=$maxLon&current_datetime=${currentDatetime.toString()}");
}
SharedPreferences prefs = await SharedPreferences.getInstance();
var accessToken = prefs.getString("access_token") ?? "";
@@ -99,7 +100,9 @@ class _MyHomePageState extends State<ListItemMenu> {
var accessToken = prefs.getString("access_token") ?? "";
final List<Events> body = [];
if (accessToken.isNotEmpty) {
var url = Uri.parse("${globals.api}/events");
DateTime currentDateTime = new DateTime.now();
var url = Uri.parse(
"${globals.api}/events?current_datetime=${currentDateTime.toString()}");
final response = await http.get(url, headers: {
"Content-Type": "application/json",
HttpHeaders.cookieHeader: "access_token=${accessToken}"
@@ -262,10 +265,10 @@ class _MyHomePageState extends State<ListItemMenu> {
double maxLat = latitude + latDistance;
double minLon = longitude - lonDistance;
double maxLon = longitude + lonDistance;
DateTime currentDate = DateTime.now();
var url = Uri.parse("${globals.api}/events/search"
"?min_lat=$minLat&max_lat=$maxLat"
"&min_lon=$minLon&max_lon=$maxLon");
"&min_lon=$minLon&max_lon=$maxLon&current_datetime=${currentDate.toString()}");
final response = await http.get(url, headers: {
"Content-Type": "application/json",