Skip to content

Commit

Permalink
feat: date time picker at detail screen
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanRns committed May 10, 2024
1 parent 9bde0e1 commit c058e04
Showing 1 changed file with 72 additions and 28 deletions.
100 changes: 72 additions & 28 deletions evently/lib/screens/detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,39 @@ class _DetailsScreenState extends State<DetailsScreen> {
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;
},
),
),
),
],
Expand All @@ -82,26 +95,42 @@ class _DetailsScreenState extends State<DetailsScreen> {
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;
},
),
),
),
],
Expand Down Expand Up @@ -146,4 +175,19 @@ class _DetailsScreenState extends State<DetailsScreen> {
)),
);
}

_showTimerPicker({required ValueChanged<TimeOfDay?> onSelected}) {
showTimePicker(
initialTime: TimeOfDay.now(),
context: context,
).then((value) => onSelected(value!));
}

_showDatePicker({required ValueChanged<DateTime?> onSelected}) {
showDatePicker(
context: context,
firstDate: DateTime.now(),
lastDate: DateTime.now(),
).then((value) => onSelected(value!));
}
}

0 comments on commit c058e04

Please sign in to comment.