diff --git a/covas_mobile/lib/pages/EditEvent.dart b/covas_mobile/lib/pages/EditEvent.dart index 0ebb8cb..fedc2bb 100644 --- a/covas_mobile/lib/pages/EditEvent.dart +++ b/covas_mobile/lib/pages/EditEvent.dart @@ -8,6 +8,8 @@ import 'package:textfield_tags/textfield_tags.dart'; import 'dart:convert'; import 'dart:io'; + +import 'dart:typed_data'; import '../classes/events.dart'; import 'ItemMenu.dart'; @@ -206,12 +208,41 @@ class _EditEventState extends State if (responseGet.statusCode == 200) { var events = jsonDecode(utf8.decode(responseGet.bodyBytes)); if (events.length > 0) { - showErrorDialog(context, "Evenement deja existant"); + if (events[0]["id"] != widget.events!.id) { + showErrorDialog(context, "Evenement deja existant"); + } return; } } + if (widget.imgPath.isNotEmpty) { + final params = { + 'expiration': '15552000', + 'key': dotenv.env["IMGBB_API_KEY"], + }; + print("Post Img"); + final urlPost = Uri.parse('https://api.imgbb.com/1/upload') + .replace(queryParameters: params); + File image = File(widget.imgPath); + Uint8List _bytes = await image.readAsBytes(); + String _base64String = base64.encode(_bytes); + + final req = http.MultipartRequest('POST', urlPost) + ..fields['image'] = _base64String; + + final stream = await req.send(); + final res = await http.Response.fromStream(stream); + + final status = res.statusCode; + print("code status imgbb ${status}"); + if (status != 200) { + showErrorDialog(context, "Image non posté"); + return; + } + var body = json.decode(utf8.decode(res.bodyBytes)); + imgUrl = body["data"]["url"]; + } var urlPut = Uri.parse("${globals.api}/events/${widget.events!.id}"); var responsePut = await http.put(urlPut,