Skip to content

Commit

Permalink
fix(mobile): selecting date from cupertino date widget resets time (A…
Browse files Browse the repository at this point in the history
  • Loading branch information
richardshiue authored Nov 14, 2024
1 parent 941b7cf commit 8120656
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class _TimePicker extends StatelessWidget {
use24hFormat: timeFormat == TimeFormatPB.TwentyFourHour,
mode: CupertinoDatePickerMode.date,
);
handleDateTimePickerResult(result, isStartDay);
handleDateTimePickerResult(result, isStartDay, true);
},
child: Padding(
padding: const EdgeInsets.symmetric(
Expand All @@ -363,7 +363,7 @@ class _TimePicker extends StatelessWidget {
use24hFormat: timeFormat == TimeFormatPB.TwentyFourHour,
mode: CupertinoDatePickerMode.date,
);
handleDateTimePickerResult(result, isStartDay);
handleDateTimePickerResult(result, isStartDay, true);
},
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
Expand All @@ -389,7 +389,7 @@ class _TimePicker extends StatelessWidget {
use24hFormat: timeFormat == TimeFormatPB.TwentyFourHour,
mode: CupertinoDatePickerMode.time,
);
handleDateTimePickerResult(result, isStartDay);
handleDateTimePickerResult(result, isStartDay, false);
},
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
Expand Down Expand Up @@ -461,11 +461,27 @@ class _TimePicker extends StatelessWidget {
);
}

void handleDateTimePickerResult(DateTime? result, bool isStartDay) {
void handleDateTimePickerResult(
DateTime? result,
bool isStartDay,
bool isDate,
) {
if (result == null) {
return;
} else if (isStartDay) {
onStartTimeChanged(result);
}

if (isDate) {
final date = isStartDay ? dateTime : endDateTime;

if (date != null) {
final timeComponent = Duration(hours: date.hour, minutes: date.minute);
result =
DateTime(result.year, result.month, result.day).add(timeComponent);
}
}

if (isStartDay) {
onStartTimeChanged.call(result);
} else {
onEndTimeChanged?.call(result);
}
Expand Down

0 comments on commit 8120656

Please sign in to comment.