From ac566053b139ac0eb7f5645882545134906422b3 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 9 Dec 2024 23:00:54 +0100 Subject: [PATCH] fix datepicker --- covas_mobile/lib/pages/EditEvent.dart | 48 ++++++++++++++++----------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/covas_mobile/lib/pages/EditEvent.dart b/covas_mobile/lib/pages/EditEvent.dart index 61a700d..4f5846b 100644 --- a/covas_mobile/lib/pages/EditEvent.dart +++ b/covas_mobile/lib/pages/EditEvent.dart @@ -1,3 +1,5 @@ +import 'dart:ffi'; + import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:http/http.dart' as http; @@ -54,10 +56,8 @@ class _EditEventState extends State TextEditingController endTimepicker = TextEditingController(); final _stringTagController = StringTagController(); - var dateS = null; - var timeS = null; - var dateE = null; - var timeE = null; + DateTime startDate = DateTime.now(); + DateTime endDate = DateTime.now(); List> suggestions = []; String geographicalZone = ""; String imgUrl = ""; @@ -86,10 +86,10 @@ class _EditEventState extends State lastDate: DateTime(2104)); if (pickedDate == null) return; if (position == "start") { - startDatepicker.text = DateFormat("dd-MM-yyyy").format(pickedDate); + startDatepicker.text = DateFormat("dd/MM/yyyy").format(pickedDate); } if (position == "end") { - endDatepicker.text = DateFormat("dd-MM-yyyy").format(pickedDate); + endDatepicker.text = DateFormat("dd/MM/yyyy").format(pickedDate); } } @@ -100,9 +100,16 @@ class _EditEventState extends State if ((startTimepicker.text.isEmpty) || (endTimepicker.text.isEmpty)) { time = TimeOfDay.now(); } else { - time = TimeOfDay.fromDateTime(DateTime.parse(startTimepicker.text)); + DateTime date = new DateTime.now(); + date = date.copyWith( + hour: int.parse(startTimepicker.text.split(":")[0]), + minute: int.parse(startTimepicker.text.split(":")[1])); + time = TimeOfDay.fromDateTime(date); if (position == "end") { - time = TimeOfDay.fromDateTime(DateTime.parse(endTimepicker.text)); + date = date.copyWith( + hour: int.parse(endTimepicker.text.split(":")[0]), + minute: int.parse(endTimepicker.text.split(":")[1])); + time = TimeOfDay.fromDateTime(date); } } @@ -132,7 +139,8 @@ class _EditEventState extends State } String formatDate(String date) { - var splitedDate = date.split("-"); + var splitedDate = date.split("/"); + var day = splitedDate[0]; var month = splitedDate[1]; var year = splitedDate[2]; @@ -164,14 +172,15 @@ class _EditEventState extends State formerDesc = convertNulltoEmptyString(events["description"]); formerTags = List.from(events['tags'] as List); formerOrga = List.from(events['organizers'] as List); - final startDate = DateTime.parse(events["start_date"]); - dateS = DateFormat.yMd().format(startDate); - timeS = DateFormat.Hm().format(startDate); + startDate = DateTime.parse(events["start_date"]); + //dateS = DateFormat.yMd().format(startDate); + //print("startdate : ${dateS}"); + //timeS = DateFormat.Hm().format(startDate); - final endDate = DateTime.parse(events["end_date"]); + endDate = DateTime.parse(events["end_date"]); - dateE = DateFormat.yMd().format(endDate); - timeE = DateFormat.Hm().format(endDate); + //dateE = DateFormat.yMd().format(endDate); + //timeE = DateFormat.Hm().format(endDate); if (events["imgUrl"] != null) { formerImage = events["imgUrl"]; } @@ -227,10 +236,11 @@ 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 = DateFormat("dd-MM-yyyy").format(dateS); - startTimepicker.text = timeS.toString(); - endDatepicker.text = DateFormat("dd-MM-yyyy").format(dateE); - endTimepicker.text = timeE.toString(); + startDatepicker.text = + DateFormat("dd/MM/yyyy").format(startDate).toString(); + startTimepicker.text = DateFormat("HH:mm").format(startDate).toString(); + endDatepicker.text = DateFormat("dd/MM/yyyy").format(endDate).toString(); + endTimepicker.text = DateFormat("HH:mm").format(endDate).toString(); initialOrga = formerOrga; inputGeo.text = formerMap; imgUrl = formerImage;