From 4af1d12283e6433f9843b78d052e19dd557a45de Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 25 Jul 2024 21:49:52 +0200 Subject: [PATCH] search events on backend --- .../lib/pages/DisplayPictureScreen.dart | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index 2807f41..b26da97 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -4,10 +4,14 @@ import '../classes/descriptionImage.dart'; import '../classes/alert.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_gemini/flutter_gemini.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:http/http.dart' as http; import 'dart:io'; import 'dart:convert'; +import '../variable/globals.dart' as globals; + void main() { runApp(MyApp()); } @@ -65,12 +69,30 @@ class DisplayPictureScreenState extends State Future searchEvents(String json) async { print(json); + SharedPreferences prefs = await SharedPreferences.getInstance(); + Map jsonData = jsonDecode(json); var name = jsonData["name"]; var place = jsonData["place"]; - var message = "Nom : ${name}\nLieu: ${place}"; - print(message); - showDescImageAddDialog(context, message); + var accessToken = prefs.getString("access_token") ?? ""; + + if (accessToken.isNotEmpty) { + var urlGet = Uri.parse("${globals.api}/events?name=${name}"); + + 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) { + showDescImageAddDialog(context, "${name} n'a pas été trouvé"); + } + } + } else { + showErrorDialog(context, "Erreur de token"); + } + + //showDescImageAddDialog(context, message); } Future _getEventInfosFromImage() async {