add put http

This commit is contained in:
Valentin CZERYBA 2024-07-27 16:44:19 +02:00
parent e320fccefa
commit de527cb84b

View File

@ -3,6 +3,7 @@ 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';
@ -10,10 +11,24 @@ mixin ShowDescImageAdd<T extends StatefulWidget> on State<T> {
Future<void> addEvents(var events) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var accessToken = prefs.getString("access_token") ?? "";
List<String> send = ["toto"];
if (accessToken.isNotEmpty) {
var urlGet = Uri.parse("${globals.api}/events");
var responseGet = await http.get(urlGet,
headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'});
var urlPut = Uri.parse("${globals.api}/events");
var responsePut = await http.put(urlPut,
headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'},
body: jsonEncode({
'name': events["name"],
'place': events["place"],
'start_date': events['start_date'],
'end_date': events['start_date'],
'organizers': send,
'latitude': '0.0',
'longitude': '0.0',
}));
print("http put code status : ${responsePut.statusCode}");
print("http put body : ${responsePut.body}");
}
}