check existing event before add

This commit is contained in:
Valentin CZERYBA 2024-12-04 23:28:09 +01:00
parent 76f1de27ec
commit cf100651eb

View File

@ -9,6 +9,7 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:typed_data'; import 'dart:typed_data';
import 'ItemMenu.dart';
import '../classes/alert.dart'; import '../classes/alert.dart';
import '../classes/eventAdded.dart'; import '../classes/eventAdded.dart';
@ -176,6 +177,42 @@ class _UpdateeventImageState extends State<UpdateeventImage>
data['features'][0]['geometry']['coordinates']; data['features'][0]['geometry']['coordinates'];
final longitude = coordinates[0]; // Longitude final longitude = coordinates[0]; // Longitude
final latitude = coordinates[1]; // Latitude final latitude = coordinates[1]; // Latitude
var urlGet = Uri.parse(
"${globals.api}/events/search?item=${name}&date_event=${startDate}");
var responseGet = await http.get(urlGet, headers: {
HttpHeaders.cookieHeader: 'access_token=${accessToken}'
});
if (responseGet.statusCode == 200) {
var events = jsonDecode(utf8.decode(responseGet.bodyBytes));
print("reponse http : ${events.length}");
if (events.length == 0) {
urlGet = Uri.parse(
"${globals.api}/events/search?min_lat=$latitude&max_lat=$latitude"
"&min_lon=$longitude&max_lon=$longitude&date_event=${startDate}");
responseGet = await http.get(urlGet, headers: {
HttpHeaders.cookieHeader: 'access_token=${accessToken}'
});
if (responseGet.statusCode == 200) {
events = jsonDecode(utf8.decode(responseGet.bodyBytes));
print("reponse http : ${events.length}");
if (events.length != 0) {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) =>
ItemMenu(title: events[0]["id"])));
return;
}
}
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => ItemMenu(title: events[0]["id"])));
return;
}
}
final params = { final params = {
'expiration': '15552000', 'expiration': '15552000',