edit event without edit image
This commit is contained in:
parent
c58127342b
commit
63f6bd2af2
@ -154,12 +154,13 @@ class _EditEventState extends State<EditEvent>
|
|||||||
List<String>.from(_stringOrgaController.getTags as List);
|
List<String>.from(_stringOrgaController.getTags as List);
|
||||||
|
|
||||||
var startDateFormat = formatDate(startDatepicker.text);
|
var startDateFormat = formatDate(startDatepicker.text);
|
||||||
DateTime startDateCompare = DateTime.parse(startDateFormat);
|
//DateTime startDateCompare = DateTime.parse(startDateFormat);
|
||||||
DateTime dateNow = DateTime.now();
|
DateTime dateNow = DateTime.now();
|
||||||
var endDateFormat = formatDate(endDatepicker.text);
|
var endDateFormat = formatDate(endDatepicker.text);
|
||||||
var startDate =
|
var startDate =
|
||||||
"${startDateFormat}T${startTimepicker.text.replaceAll('-', ':')}";
|
"${startDateFormat}T${startTimepicker.text.replaceAll('-', ':')}";
|
||||||
var endDate = "${endDateFormat}T${endTimepicker.text.replaceAll('-', ':')}";
|
var endDate = "${endDateFormat}T${endTimepicker.text.replaceAll('-', ':')}";
|
||||||
|
DateTime startDateCompare = DateTime.parse(startDate);
|
||||||
if (startDateCompare.isAfter(dateNow)) {
|
if (startDateCompare.isAfter(dateNow)) {
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
var accessToken = prefs.getString("access_token") ?? "";
|
var accessToken = prefs.getString("access_token") ?? "";
|
||||||
@ -186,65 +187,23 @@ class _EditEventState extends State<EditEvent>
|
|||||||
final longitude = coordinates[0]; // Longitude
|
final longitude = coordinates[0]; // Longitude
|
||||||
final latitude = coordinates[1]; // Latitude
|
final latitude = coordinates[1]; // Latitude
|
||||||
var urlGet = Uri.parse(
|
var urlGet = Uri.parse(
|
||||||
"${globals.api}/events/search?item=${name}&date_event=${startDate}");
|
"${globals.api}/events/search?item=${name}&date_event=${startDate}&min_lat=$latitude&max_lat=$latitude"
|
||||||
|
"&min_lon=$longitude&max_lon=$longitude");
|
||||||
|
|
||||||
var responseGet = await http.get(urlGet, headers: {
|
var responseGet = await http.get(urlGet, headers: {
|
||||||
HttpHeaders.cookieHeader: 'access_token=${accessToken}'
|
HttpHeaders.cookieHeader: 'access_token=${accessToken}'
|
||||||
});
|
});
|
||||||
if (responseGet.statusCode == 200) {
|
if (responseGet.statusCode == 200) {
|
||||||
var events = jsonDecode(utf8.decode(responseGet.bodyBytes));
|
var events = jsonDecode(utf8.decode(responseGet.bodyBytes));
|
||||||
print("reponse http : ${events.length}");
|
if (events.length > 0) {
|
||||||
if (events.length == 0) {
|
showErrorDialog(context, "Evenement deja existant");
|
||||||
urlGet = Uri.parse(
|
|
||||||
"${globals.api}/events/search?min_lat=$latitude&max_lat=$latitude"
|
|
||||||
"&min_lon=$longitude&max_lon=$longitude&date_event=${startDate}");
|
|
||||||
responseGet = await http.get(urlGet, headers: {
|
|
||||||
HttpHeaders.cookieHeader: 'access_token=${accessToken}'
|
|
||||||
});
|
|
||||||
if (responseGet.statusCode == 200) {
|
|
||||||
events = jsonDecode(utf8.decode(responseGet.bodyBytes));
|
|
||||||
print("reponse http : ${events.length}");
|
|
||||||
if (events.length != 0) {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) =>
|
|
||||||
ItemMenu(title: events[0]["id"])));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => ItemMenu(title: events[0]["id"])));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final params = {
|
var urlPut =
|
||||||
'expiration': '15552000',
|
Uri.parse("${globals.api}/events/${widget.events!.id}");
|
||||||
'key': dotenv.env["IMGBB_API_KEY"],
|
|
||||||
};
|
|
||||||
print("Post Img");
|
|
||||||
final urlPost = Uri.parse('https://api.imgbb.com/1/upload')
|
|
||||||
.replace(queryParameters: params);
|
|
||||||
|
|
||||||
final req = http.MultipartRequest('POST', urlPost);
|
|
||||||
|
|
||||||
final stream = await req.send();
|
|
||||||
final res = await http.Response.fromStream(stream);
|
|
||||||
|
|
||||||
final status = res.statusCode;
|
|
||||||
print("code status imgbb ${status}");
|
|
||||||
if (status == 200) {
|
|
||||||
var body = json.decode(utf8.decode(res.bodyBytes));
|
|
||||||
String imgUrl = body["data"]["url"];
|
|
||||||
|
|
||||||
//String credentials = "${pseudo}:${password}";
|
|
||||||
//Codec<String, String> stringToBase64 = utf8.fuse(base64);
|
|
||||||
//String encoded = stringToBase64.encode(credentials);
|
|
||||||
var urlPut = Uri.parse("${globals.api}/events");
|
|
||||||
var responsePut = await http.put(urlPut,
|
var responsePut = await http.put(urlPut,
|
||||||
headers: {
|
headers: {
|
||||||
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
||||||
@ -267,7 +226,7 @@ class _EditEventState extends State<EditEvent>
|
|||||||
print(responsePut.statusCode);
|
print(responsePut.statusCode);
|
||||||
if ((responsePut.statusCode == 200) ||
|
if ((responsePut.statusCode == 200) ||
|
||||||
(responsePut.statusCode == 201)) {
|
(responsePut.statusCode == 201)) {
|
||||||
showEventDialog(context, "Evenement ${name} ajoute");
|
showEventDialog(context, "Evenement ${name} modifie");
|
||||||
} else {
|
} else {
|
||||||
var text = "";
|
var text = "";
|
||||||
switch (responsePut.statusCode) {
|
switch (responsePut.statusCode) {
|
||||||
@ -309,9 +268,6 @@ class _EditEventState extends State<EditEvent>
|
|||||||
}
|
}
|
||||||
showErrorDialog(context, text);
|
showErrorDialog(context, text);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
print("imgbb error : ${status}");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
showErrorDialog(context, "Aucune donnée geographique");
|
showErrorDialog(context, "Aucune donnée geographique");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user