fix datetpicker wip

This commit is contained in:
Valentin CZERYBA 2024-12-08 21:23:51 +01:00
parent 4b71867ee0
commit c12a957099
2 changed files with 38 additions and 29 deletions

View File

@ -54,6 +54,10 @@ class _EditEventState extends State<EditEvent>
TextEditingController endTimepicker = TextEditingController();
final _stringTagController = StringTagController();
var dateS = null;
var timeS = null;
var dateE = null;
var timeE = null;
List<Map<String, dynamic>> suggestions = [];
String geographicalZone = "";
String imgUrl = "";
@ -66,20 +70,19 @@ class _EditEventState extends State<EditEvent>
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<EditEvent>
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<EditEvent>
String formerMap = "";
String formerImage = "";
String formerDesc = "";
var date = null;
var time = null;
var dateE = null;
var timeE = null;
List<String> formerTags = [];
List<String> formerOrga = [];
@ -165,8 +165,8 @@ class _EditEventState extends State<EditEvent>
formerTags = List<String>.from(events['tags'] as List);
formerOrga = List<String>.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<EditEvent>
// _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;

View File

@ -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<ItemMenu> with ShowErrorDialog {
List<String> tags = [];
List<String> organizers = [];
String id = "";
Events? events;
@override
void initState() {
@ -104,6 +107,7 @@ class _ItemMenuState extends State<ItemMenu> 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<ItemMenu> 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),