diff --git a/covas_mobile/lib/pages/EditEvent.dart b/covas_mobile/lib/pages/EditEvent.dart index 44246f5..61a700d 100644 --- a/covas_mobile/lib/pages/EditEvent.dart +++ b/covas_mobile/lib/pages/EditEvent.dart @@ -54,6 +54,10 @@ class _EditEventState extends State TextEditingController endTimepicker = TextEditingController(); final _stringTagController = StringTagController(); + var dateS = null; + var timeS = null; + var dateE = null; + var timeE = null; List> suggestions = []; String geographicalZone = ""; String imgUrl = ""; @@ -66,20 +70,19 @@ class _EditEventState extends State onTapFunctionDatePicker( {required BuildContext context, required String position}) async { - String date = "start_date"; - if (position == "end") { - date = "end_date"; - } - DateTime dateEvent; - if (events[date].toString().isEmpty) { - dateEvent = DateTime.now(); + DateTime date; + if ((startDatepicker.text.isEmpty) || (endDatepicker.text.isEmpty)) { + date = DateTime.now(); } else { - dateEvent = DateTime.parse(events[date]); + date = DateTime.parse(formatDate(startDatepicker.text)); + if (position == "end") { + date = DateTime.parse(formatDate(endDatepicker.text)); + } } DateTime? pickedDate = await showDatePicker( context: context, - firstDate: dateEvent, - initialDate: dateEvent, + firstDate: date, + initialDate: date, lastDate: DateTime(2104)); if (pickedDate == null) return; if (position == "start") { @@ -92,18 +95,19 @@ class _EditEventState extends State onTapFunctionTimePicker( {required BuildContext context, required String position}) async { - String date = "start_date"; - if (position == "end") { - date = "end_date"; - } - TimeOfDay timeEvent; - if (widget.events[date].toString().isEmpty) { - timeEvent = TimeOfDay.now(); + TimeOfDay time; + + if ((startTimepicker.text.isEmpty) || (endTimepicker.text.isEmpty)) { + time = TimeOfDay.now(); } else { - timeEvent = TimeOfDay.fromDateTime(DateTime.parse(widget.events[date])); + time = TimeOfDay.fromDateTime(DateTime.parse(startTimepicker.text)); + if (position == "end") { + time = TimeOfDay.fromDateTime(DateTime.parse(endTimepicker.text)); + } } + TimeOfDay? pickedDate = - await showTimePicker(context: context, initialTime: timeEvent); + await showTimePicker(context: context, initialTime: time); if (pickedDate == null) return; if (position == "start") { startTimepicker.text = pickedDate.format(context); @@ -143,10 +147,6 @@ class _EditEventState extends State String formerMap = ""; String formerImage = ""; String formerDesc = ""; - var date = null; - var time = null; - var dateE = null; - var timeE = null; List formerTags = []; List formerOrga = []; @@ -165,8 +165,8 @@ class _EditEventState extends State formerTags = List.from(events['tags'] as List); formerOrga = List.from(events['organizers'] as List); final startDate = DateTime.parse(events["start_date"]); - date = DateFormat.yMd().format(startDate); - time = DateFormat.Hm().format(startDate); + dateS = DateFormat.yMd().format(startDate); + timeS = DateFormat.Hm().format(startDate); final endDate = DateTime.parse(events["end_date"]); @@ -227,9 +227,9 @@ class _EditEventState extends State // _counter without calling setState(), then the build method would not be // called again, and so nothing would appear to happen. inputName.text = formerName; - startDatepicker.text = date.toString(); - startTimepicker.text = time.toString(); - endDatepicker.text = dateE.toString(); + startDatepicker.text = DateFormat("dd-MM-yyyy").format(dateS); + startTimepicker.text = timeS.toString(); + endDatepicker.text = DateFormat("dd-MM-yyyy").format(dateE); endTimepicker.text = timeE.toString(); initialOrga = formerOrga; inputGeo.text = formerMap; diff --git a/covas_mobile/lib/pages/ItemMenu.dart b/covas_mobile/lib/pages/ItemMenu.dart index be0c762..d5c7ed8 100644 --- a/covas_mobile/lib/pages/ItemMenu.dart +++ b/covas_mobile/lib/pages/ItemMenu.dart @@ -18,6 +18,7 @@ import '../classes/events.dart'; import 'ListItemMenu.dart'; import 'MapboxPages.dart'; import 'ListItemByOrganizers.dart'; +import 'EditEvent.dart'; void main() { initializeDateFormatting("fr_FR", null).then((_) => (const MyApp())); @@ -76,6 +77,8 @@ class _ItemMenuState extends State with ShowErrorDialog { List tags = []; List organizers = []; + String id = ""; + Events? events; @override void initState() { @@ -104,6 +107,7 @@ class _ItemMenuState extends State with ShowErrorDialog { if (responseGet.statusCode == 200) { stderr.writeln('Username : ${responseGet.body}'); var events = jsonDecode(utf8.decode(responseGet.bodyBytes)); + id = events["id"]; formerName = events["name"]; formerMap = "${events["place"]}"; formerDesc = events["description"]; @@ -397,7 +401,12 @@ class _ItemMenuState extends State with ShowErrorDialog { ), ), floatingActionButton: FloatingActionButton( - onPressed: () {}, + onPressed: () { + Navigator.push( + context, + MaterialPageRoute(builder: (_) => EditEvent(id: id)), + ); + }, backgroundColor: Colors.blue, tooltip: 'Recherche', child: const Icon(Icons.edit, color: Colors.white),