2024-07-28 21:54:37 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
//import 'MyHomePage.dart';
|
|
|
|
import 'ListItemMenu.dart';
|
|
|
|
|
|
|
|
import '../classes/alert.dart';
|
2024-07-30 23:46:15 +02:00
|
|
|
import '../classes/eventAdded.dart';
|
2024-07-28 21:54:37 +02:00
|
|
|
|
|
|
|
import '../variable/globals.dart' as globals;
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(MyApp());
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
2024-07-30 23:19:37 +02:00
|
|
|
Map<String, dynamic> events = {};
|
2024-07-28 21:54:37 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
debugShowCheckedModeBanner: false,
|
2024-07-30 23:19:37 +02:00
|
|
|
home: UpdateeventImage(events: events),
|
2024-07-28 21:54:37 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class UpdateeventImage extends StatefulWidget {
|
2024-07-30 23:19:37 +02:00
|
|
|
const UpdateeventImage({Key? key, required this.events}) : super(key: key);
|
|
|
|
final Map<String, dynamic> events;
|
|
|
|
|
2024-07-28 21:54:37 +02:00
|
|
|
@override
|
|
|
|
_UpdateeventImageState createState() => _UpdateeventImageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UpdateeventImageState extends State<UpdateeventImage>
|
2024-07-30 23:46:15 +02:00
|
|
|
with ShowErrorDialog, ShowEventDialog {
|
2024-07-30 23:19:37 +02:00
|
|
|
TextEditingController inputName = TextEditingController();
|
|
|
|
TextEditingController inputPlace = TextEditingController();
|
|
|
|
TextEditingController inputDate = TextEditingController();
|
|
|
|
|
2024-07-30 23:46:15 +02:00
|
|
|
Future<void> _updateEvent(BuildContext context) async {
|
2024-07-28 21:54:37 +02:00
|
|
|
var url = Uri.parse("${globals.api}/token");
|
2024-07-30 23:46:15 +02:00
|
|
|
var name = inputName.text;
|
|
|
|
var place = inputPlace.text;
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
var accessToken = prefs.getString("access_token") ?? "";
|
|
|
|
List<String> send = ["toto"];
|
|
|
|
if (accessToken.isNotEmpty) {
|
2024-07-28 21:54:37 +02:00
|
|
|
try {
|
|
|
|
//String credentials = "${pseudo}:${password}";
|
|
|
|
//Codec<String, String> stringToBase64 = utf8.fuse(base64);
|
|
|
|
//String encoded = stringToBase64.encode(credentials);
|
2024-07-30 23:46:15 +02:00
|
|
|
var urlPut = Uri.parse("${globals.api}/events");
|
|
|
|
var responsePut = await http.put(urlPut,
|
2024-07-28 21:54:37 +02:00
|
|
|
headers: {
|
2024-07-30 23:46:15 +02:00
|
|
|
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
|
|
|
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
|
|
|
HttpHeaders.contentTypeHeader: 'application/json'
|
2024-07-28 21:54:37 +02:00
|
|
|
},
|
2024-07-30 23:46:15 +02:00
|
|
|
body: jsonEncode({
|
|
|
|
'name': name,
|
|
|
|
'place': place,
|
|
|
|
'start_date': widget.events["date"],
|
|
|
|
'end_date': widget.events['date'],
|
|
|
|
'organizers': send,
|
|
|
|
'latitude': '0.0',
|
|
|
|
'longitude': '0.0',
|
|
|
|
}));
|
|
|
|
print(responsePut.statusCode);
|
|
|
|
if ((responsePut.statusCode == 200) ||
|
|
|
|
(responsePut.statusCode == 201)) {
|
|
|
|
showEventDialog(context, "Evenement ${name} ajoute");
|
2024-07-28 21:54:37 +02:00
|
|
|
} else {
|
|
|
|
var text = "";
|
2024-07-30 23:46:15 +02:00
|
|
|
switch (responsePut.statusCode) {
|
2024-07-28 21:54:37 +02:00
|
|
|
case 400:
|
|
|
|
{
|
|
|
|
text = "Requête mal construite";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 406:
|
|
|
|
{
|
|
|
|
text = "Mot de passe incorrect";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 404:
|
|
|
|
{
|
|
|
|
text = "Utilisateur inconnu";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 403:
|
|
|
|
{
|
|
|
|
text = "Utilisateur desactive";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 410:
|
|
|
|
{
|
|
|
|
text = "Token invalide";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 500:
|
|
|
|
{
|
|
|
|
text = "Probleme interne du serveur";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
text = "Probleme d'authentification inconnu";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
showErrorDialog(context, text);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
showErrorDialog(context, "${e}");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
showErrorDialog(context, "Champ vide");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void start() async {
|
2024-07-30 23:19:37 +02:00
|
|
|
inputName.text = widget.events["name"];
|
|
|
|
inputPlace.text = widget.events["place"];
|
2024-07-28 21:54:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
start();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text("Login Page"),
|
|
|
|
backgroundColor: Colors.blue,
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
),
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 60.0),
|
|
|
|
child: Center(
|
|
|
|
child: Container(
|
|
|
|
width: 200,
|
|
|
|
height: 150,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.red,
|
|
|
|
borderRadius: BorderRadius.circular(50.0)),
|
|
|
|
child: Image.asset('./images/flutter.png')),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
|
|
|
child: TextField(
|
2024-07-30 23:19:37 +02:00
|
|
|
controller: inputName,
|
2024-07-28 21:54:37 +02:00
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
2024-07-30 23:19:37 +02:00
|
|
|
labelText: 'Nom',
|
|
|
|
hintText: 'Modifier le nom de l\'évènement'),
|
2024-07-28 21:54:37 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
|
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
|
|
child: TextField(
|
2024-07-30 23:19:37 +02:00
|
|
|
controller: inputPlace,
|
2024-07-28 21:54:37 +02:00
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
2024-07-30 23:19:37 +02:00
|
|
|
labelText: 'Lieu',
|
|
|
|
hintText: 'Entrer le lieu'),
|
2024-07-28 21:54:37 +02:00
|
|
|
),
|
|
|
|
),
|
2024-07-30 23:19:37 +02:00
|
|
|
SizedBox(
|
|
|
|
height: 30,
|
2024-07-28 21:54:37 +02:00
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 50,
|
|
|
|
width: 250,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.blue, borderRadius: BorderRadius.circular(20)),
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: () {
|
2024-07-30 23:46:15 +02:00
|
|
|
_updateEvent(context);
|
2024-07-28 21:54:37 +02:00
|
|
|
},
|
|
|
|
child: Text(
|
2024-07-30 23:19:37 +02:00
|
|
|
'Ajouter',
|
2024-07-28 21:54:37 +02:00
|
|
|
style: TextStyle(color: Colors.white, fontSize: 25),
|
|
|
|
),
|
|
|
|
),
|
2024-07-30 23:19:37 +02:00
|
|
|
)
|
2024-07-28 21:54:37 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|