search events on backend
This commit is contained in:
parent
cf8d636f94
commit
4af1d12283
@ -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<DisplayPictureScreen>
|
||||
|
||||
Future<void> searchEvents(String json) async {
|
||||
print(json);
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
|
||||
Map<String, dynamic> 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<void> _getEventInfosFromImage() async {
|
||||
|
Loading…
x
Reference in New Issue
Block a user