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