hotfix/duplicate-event #43
@ -102,6 +102,41 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
|
|||||||
"L'IA de Google n'a pas su analyser l'image. Recommecer avec une autre");
|
"L'IA de Google n'a pas su analyser l'image. Recommecer avec une autre");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _showErrorDialog(BuildContext context, String title, String message) {
|
||||||
|
showAlertDialog(context, title, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>?> _fetchGeolocation(String place) async {
|
||||||
|
final apiKey = dotenv.env['PLACE_API_KEY'] ?? '';
|
||||||
|
final response = await http.get(Uri.parse(
|
||||||
|
'https://maps.googleapis.com/maps/api/place/textsearch/json?query=${place}}&key=$apiKey'));
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
final data = json.decode(response.body);
|
||||||
|
if (data['results'].isNotEmpty) {
|
||||||
|
return data['results'][0]['geometry']['location'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> _isDuplicateEvent(String accessToken,
|
||||||
|
Map<String, dynamic> jsonData, Map<String, dynamic> location) async {
|
||||||
|
final url = Uri.parse(
|
||||||
|
"${globals.api}/events/search?item=${jsonData["name"]}&date_event=${jsonData["start_date"]}"
|
||||||
|
"&min_lat=${location['lat']}&max_lat=${location['lat']}"
|
||||||
|
"&min_lon=${location['lng']}&max_lon=${location['lng']}");
|
||||||
|
|
||||||
|
final response = await http.get(url,
|
||||||
|
headers: {HttpHeaders.cookieHeader: 'access_token=$accessToken'});
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
final events = jsonDecode(utf8.decode(response.bodyBytes));
|
||||||
|
return events.isNotEmpty;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> searchEvents(String json, String imagePath) async {
|
Future<void> searchEvents(String json, String imagePath) async {
|
||||||
print(json.replaceAll("'''json", '').replaceAll("'''", ""));
|
print(json.replaceAll("'''json", '').replaceAll("'''", ""));
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
@ -116,13 +151,22 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
|
|||||||
var accessToken = prefs.getString("access_token") ?? "";
|
var accessToken = prefs.getString("access_token") ?? "";
|
||||||
|
|
||||||
if (accessToken.isNotEmpty) {
|
if (accessToken.isNotEmpty) {
|
||||||
var urlGet = Uri.parse(
|
final location = await _fetchGeolocation(place);
|
||||||
"${globals.api}/events/search?item=${name}&date_event=${date}");
|
if (location == null) {
|
||||||
|
_showErrorDialog(
|
||||||
|
context, "Erreur serveur", "Aucune donnée geographique");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var responseGet = await http.get(urlGet,
|
final url = Uri.parse(
|
||||||
headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'});
|
"${globals.api}/events/search?item=${name}&date_event=${date}"
|
||||||
if (responseGet.statusCode == 200) {
|
"&min_lat=${location['lat']}&max_lat=${location['lat']}"
|
||||||
var events = jsonDecode(utf8.decode(responseGet.bodyBytes));
|
"&min_lon=${location['lng']}&max_lon=${location['lng']}");
|
||||||
|
|
||||||
|
final response = await http.get(url,
|
||||||
|
headers: {HttpHeaders.cookieHeader: 'access_token=$accessToken'});
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
var events = jsonDecode(utf8.decode(response.bodyBytes));
|
||||||
print("reponse http : ${events.length}");
|
print("reponse http : ${events.length}");
|
||||||
if (events.length == 0) {
|
if (events.length == 0) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
@ -138,7 +182,7 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showAlertDialog(context, 'Erreur de reponse',
|
showAlertDialog(context, 'Erreur de reponse',
|
||||||
"response status code update : ${responseGet.statusCode}");
|
"response status code update : ${response.statusCode}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showAlertDialog(context, "Erreur de reponse", "Erreur de token");
|
showAlertDialog(context, "Erreur de reponse", "Erreur de token");
|
||||||
@ -162,7 +206,7 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
|
|||||||
gemini
|
gemini
|
||||||
.textAndImage(
|
.textAndImage(
|
||||||
text:
|
text:
|
||||||
"Peux-tu donner le nom, la date avec l'année actuelle ou d'une année future proche et le lieu de l'évènement sous format JSON (sans le caratère json au début de la chaine de caractère) avec les valeurs suivantes : name, place, description, tags (tableau sans espace), organizers (tableau), start_date et end_date (si le end_date est vide, alors donnez une valeur de six de plus par rapport à start_date) sous le format en YYYY-MM-DD HH:mm:ssZ",
|
"Peux-tu donner le nom, la date (si l'année n'est pas précisé, mettez l'année actuelle ou future) et le lieu de l'évènement sous format JSON (sans le caratère json au début de la chaine de caractère) avec les valeurs suivantes : name, place, description, tags (tableau sans espace), organizers (tableau), start_date et end_date (si le end_date est vide, alors donnez une valeur de six de plus par rapport à start_date) sous le format en YYYY-MM-DD HH:mm:ssZ",
|
||||||
images: [file.readAsBytesSync()],
|
images: [file.readAsBytesSync()],
|
||||||
modelName: "models/gemini-1.5-pro-latest")
|
modelName: "models/gemini-1.5-pro-latest")
|
||||||
.then((value) => searchEvents(
|
.then((value) => searchEvents(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user