search events on backend

This commit is contained in:
Valentin CZERYBA 2024-07-25 21:49:52 +02:00
parent cf8d636f94
commit 4af1d12283

View File

@ -4,10 +4,14 @@ import '../classes/descriptionImage.dart';
import '../classes/alert.dart'; import '../classes/alert.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_gemini/flutter_gemini.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:io';
import 'dart:convert'; import 'dart:convert';
import '../variable/globals.dart' as globals;
void main() { void main() {
runApp(MyApp()); runApp(MyApp());
} }
@ -65,12 +69,30 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
Future<void> searchEvents(String json) async { Future<void> searchEvents(String json) async {
print(json); print(json);
SharedPreferences prefs = await SharedPreferences.getInstance();
Map<String, dynamic> jsonData = jsonDecode(json); Map<String, dynamic> jsonData = jsonDecode(json);
var name = jsonData["name"]; var name = jsonData["name"];
var place = jsonData["place"]; var place = jsonData["place"];
var message = "Nom : ${name}\nLieu: ${place}"; var accessToken = prefs.getString("access_token") ?? "";
print(message);
showDescImageAddDialog(context, message); 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<void> _getEventInfosFromImage() async { Future<void> _getEventInfosFromImage() async {