mobile-flutter/covas_mobile/lib/classes/getEventImage.dart

68 lines
2.2 KiB
Dart
Raw Normal View History

2024-07-17 23:39:51 +02:00
import 'package:flutter/material.dart';
2024-07-25 22:23:45 +02:00
import 'events.dart';
2024-07-26 15:06:15 +02:00
import '../variable/globals.dart' as globals;
import 'package:http/http.dart' as http;
import 'dart:io';
2024-07-27 16:44:19 +02:00
import 'dart:convert';
2024-07-17 23:39:51 +02:00
2024-07-25 22:44:06 +02:00
import 'package:shared_preferences/shared_preferences.dart';
2024-07-27 18:53:02 +02:00
mixin ShowDescImageGet<T extends StatefulWidget> on State<T> {
Future<void> getEvents(var events) async {
2024-07-25 22:44:06 +02:00
SharedPreferences prefs = await SharedPreferences.getInstance();
var accessToken = prefs.getString("access_token") ?? "";
2024-07-27 16:44:19 +02:00
List<String> send = ["toto"];
2024-07-26 15:06:15 +02:00
if (accessToken.isNotEmpty) {
2024-07-27 16:44:19 +02:00
var urlPut = Uri.parse("${globals.api}/events");
2024-07-27 17:06:13 +02:00
print("start date : ${events["start_date"]}");
2024-07-27 16:44:19 +02:00
var responsePut = await http.put(urlPut,
2024-07-27 17:06:13 +02:00
headers: {
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
HttpHeaders.contentTypeHeader: 'application/json'
},
2024-07-27 16:44:19 +02:00
body: jsonEncode({
'name': events["name"],
'place': events["place"],
2024-07-27 17:06:13 +02:00
'start_date': events['date'],
'end_date': events['date'],
2024-07-27 16:44:19 +02:00
'organizers': send,
'latitude': '0.0',
'longitude': '0.0',
}));
print("http put code status : ${responsePut.statusCode}");
print("http put body : ${responsePut.body}");
2024-07-26 15:06:15 +02:00
}
2024-07-25 22:44:06 +02:00
}
2024-07-27 19:40:02 +02:00
void showDescImageGetDialog(BuildContext context, var events) {
2024-07-17 23:39:51 +02:00
// Create AlertDialog
2024-07-25 22:23:45 +02:00
String name = events['name'];
2024-07-17 23:39:51 +02:00
AlertDialog dialog = AlertDialog(
2024-07-27 18:53:02 +02:00
title: Text("Voir la description de l'evenement"),
content: Text("${name} a été trouvé. Voulez-vous voir sa description ? "),
2024-07-17 23:39:51 +02:00
actions: [
2024-07-25 22:34:35 +02:00
TextButton(
child: Text("Annuler"),
2024-07-25 22:23:45 +02:00
onPressed: () {
Navigator.of(context).pop("Yes, Of course!"); // Return value
}),
2024-07-25 22:34:35 +02:00
TextButton(
child: Text("Oui"),
2024-07-17 23:39:51 +02:00
onPressed: () {
2024-07-27 18:53:02 +02:00
getEvents(events); // Return value
2024-07-17 23:39:51 +02:00
}),
],
);
// Call showDialog function to show dialog.
Future futureValue = showDialog(
context: context,
builder: (BuildContext context) {
return dialog;
});
}
}