redirect to item list menu
This commit is contained in:
parent
cadd3ef2bf
commit
c3937a3e30
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../main.dart';
|
||||
import '../pages/ListItemMenu.dart';
|
||||
|
||||
mixin ShowEventDialog<T extends StatefulWidget> on State<T> {
|
||||
void showEventDialog(BuildContext context, String text) {
|
||||
@ -16,7 +16,10 @@ mixin ShowEventDialog<T extends StatefulWidget> on State<T> {
|
||||
textStyle:
|
||||
TextStyle(fontSize: 15, fontWeight: FontWeight.normal)),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop("Yes, Of course!"); // Return value
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => ListItemMenu())); // Return value
|
||||
}),
|
||||
],
|
||||
);
|
||||
|
@ -9,6 +9,7 @@ import 'dart:io';
|
||||
import 'ListItemMenu.dart';
|
||||
|
||||
import '../classes/alert.dart';
|
||||
import '../classes/eventAdded.dart';
|
||||
|
||||
import '../variable/globals.dart' as globals;
|
||||
|
||||
@ -36,60 +37,46 @@ class UpdateeventImage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _UpdateeventImageState extends State<UpdateeventImage>
|
||||
with ShowErrorDialog {
|
||||
with ShowErrorDialog, ShowEventDialog {
|
||||
TextEditingController inputName = TextEditingController();
|
||||
TextEditingController inputPlace = TextEditingController();
|
||||
TextEditingController inputDate = TextEditingController();
|
||||
|
||||
Future<void> _login(BuildContext context) async {
|
||||
Future<void> _updateEvent(BuildContext context) async {
|
||||
var url = Uri.parse("${globals.api}/token");
|
||||
var pseudo = inputName.text;
|
||||
var password = inputPlace.text;
|
||||
print("get login");
|
||||
print(pseudo.isNotEmpty);
|
||||
print(password.isNotEmpty);
|
||||
if ((pseudo.isNotEmpty) && (password.isNotEmpty)) {
|
||||
print(url);
|
||||
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) {
|
||||
try {
|
||||
//String credentials = "${pseudo}:${password}";
|
||||
//Codec<String, String> stringToBase64 = utf8.fuse(base64);
|
||||
//String encoded = stringToBase64.encode(credentials);
|
||||
var response = await http.post(url,
|
||||
// headers: {
|
||||
// HttpHeaders.authorizationHeader: 'Basic $encoded',
|
||||
//}
|
||||
var urlPut = Uri.parse("${globals.api}/events");
|
||||
var responsePut = await http.put(urlPut,
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
||||
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
||||
HttpHeaders.contentTypeHeader: 'application/json'
|
||||
},
|
||||
body: {
|
||||
"username": "${pseudo}",
|
||||
"password": "${password}"
|
||||
});
|
||||
print(response.statusCode);
|
||||
if ((response.statusCode == 200) || (response.statusCode == 201)) {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
|
||||
var cookies = response.headers["set-cookie"].toString().split(";");
|
||||
for (var cookie in cookies) {
|
||||
var cookiesMany = cookie.split(",");
|
||||
for (var cookie2 in cookiesMany) {
|
||||
switch (cookie2.split("=")[0]) {
|
||||
case "access_token":
|
||||
{
|
||||
prefs.setString("access_token", cookie2.split("=")[1]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Navigator.push(
|
||||
context, MaterialPageRoute(builder: (_) => ListItemMenu()));
|
||||
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");
|
||||
} else {
|
||||
var text = "";
|
||||
switch (response.statusCode) {
|
||||
switch (responsePut.statusCode) {
|
||||
case 400:
|
||||
{
|
||||
text = "Requête mal construite";
|
||||
@ -204,7 +191,7 @@ class _UpdateeventImageState extends State<UpdateeventImage>
|
||||
color: Colors.blue, borderRadius: BorderRadius.circular(20)),
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
_login(context);
|
||||
_updateEvent(context);
|
||||
},
|
||||
child: Text(
|
||||
'Ajouter',
|
||||
|
Loading…
x
Reference in New Issue
Block a user