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

68 lines
2.2 KiB
Dart

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