From c058e049d606cb5cf84100cacaadaa1cc2cedbd2 Mon Sep 17 00:00:00 2001 From: AhsanRns Date: Fri, 10 May 2024 17:44:20 +0500 Subject: [PATCH] feat: date time picker at detail screen --- evently/lib/screens/detail_screen.dart | 100 ++++++++++++++++++------- 1 file changed, 72 insertions(+), 28 deletions(-) diff --git a/evently/lib/screens/detail_screen.dart b/evently/lib/screens/detail_screen.dart index 6408b7e44d..963e436601 100644 --- a/evently/lib/screens/detail_screen.dart +++ b/evently/lib/screens/detail_screen.dart @@ -54,26 +54,39 @@ class _DetailsScreenState extends State { Row( children: [ Expanded( - child: EventlyTextField( - enable: false, - label: LocaleKeys.start_date.tr(), - controller: TextEditingController(text: provider.startDate), - textCapitalization: TextCapitalization.sentences, - validator: (value) { - return null; + child: GestureDetector( + onTap: () async { + _showDatePicker(onSelected: (DateTime? val) { + if (val == null) return; + provider.setStartDate = DateFormat("dd-MM-yyyy").format(val); + }); }, + child: EventlyTextField( + enable: false, + label: LocaleKeys.start_date.tr(), + controller: TextEditingController(text: provider.startDate), + textCapitalization: TextCapitalization.sentences, + ), ), ), HorizontalSpace(20.w), Expanded( - child: EventlyTextField( - enable: false, - label: LocaleKeys.end_date.tr(), - controller: TextEditingController(text: provider.endDate), - textCapitalization: TextCapitalization.sentences, - validator: (value) { - return null; + child: GestureDetector( + onTap: () { + _showDatePicker(onSelected: (DateTime? val) { + if (val == null) return; + provider.setEndDate = DateFormat("dd-MM-yyyy").format(val); + }); }, + child: EventlyTextField( + enable: false, + label: LocaleKeys.end_date.tr(), + controller: TextEditingController(text: provider.endDate), + textCapitalization: TextCapitalization.sentences, + validator: (value) { + return null; + }, + ), ), ), ], @@ -82,26 +95,42 @@ class _DetailsScreenState extends State { Row( children: [ Expanded( - child: EventlyTextField( - enable: false, - label: LocaleKeys.start_time.tr(), - controller: TextEditingController(text: provider.startTime), - textCapitalization: TextCapitalization.sentences, - validator: (value) { - return null; + child: GestureDetector( + onTap: () { + _showTimerPicker(onSelected: (TimeOfDay? timeOfDay) { + if (timeOfDay == null) return; + provider.setStartTime = '${timeOfDay.hour}:${timeOfDay.minute}'; + }); }, + child: EventlyTextField( + enable: false, + label: LocaleKeys.start_time.tr(), + controller: TextEditingController(text: provider.startTime), + textCapitalization: TextCapitalization.sentences, + validator: (value) { + return null; + }, + ), ), ), HorizontalSpace(20.w), Expanded( - child: EventlyTextField( - enable: false, - label: LocaleKeys.end_time.tr(), - controller: TextEditingController(text: provider.endTime), - textCapitalization: TextCapitalization.sentences, - validator: (value) { - return null; + child: GestureDetector( + onTap: () { + _showTimerPicker(onSelected: (TimeOfDay? timeOfDay) { + if (timeOfDay == null) return; + provider.setEndTime = '${timeOfDay.hour}:${timeOfDay.minute}'; + }); }, + child: EventlyTextField( + enable: false, + label: LocaleKeys.end_time.tr(), + controller: TextEditingController(text: provider.endTime), + textCapitalization: TextCapitalization.sentences, + validator: (value) { + return null; + }, + ), ), ), ], @@ -146,4 +175,19 @@ class _DetailsScreenState extends State { )), ); } + + _showTimerPicker({required ValueChanged onSelected}) { + showTimePicker( + initialTime: TimeOfDay.now(), + context: context, + ).then((value) => onSelected(value!)); + } + + _showDatePicker({required ValueChanged onSelected}) { + showDatePicker( + context: context, + firstDate: DateTime.now(), + lastDate: DateTime.now(), + ).then((value) => onSelected(value!)); + } }