Refactor to eliminate duplicate DateFormat creation

Co-authored-by: LucasXu0 <11863087+LucasXu0@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-10-27 01:50:38 +00:00
parent 7b4025108e
commit 7ae906273a

View File

@ -239,19 +239,16 @@ class _DateTimeTextFieldState extends State<DateTimeTextField> {
// If the string includes time, try to parse with the combined format
if (widget.includeTime && widget.timeFormat != null) {
final combinedFormat = DateFormat(
"${widget.dateFormat.pattern} ${widget.timeFormat!.pattern}",
);
try {
final combinedFormat = DateFormat(
"${widget.dateFormat.pattern} ${widget.timeFormat!.pattern}",
);
final result = combinedFormat.parseStrict(trimmedString);
if (!result.isBefore(kFirstDay) && !result.isAfter(kLastDay)) {
return result;
}
} catch (_) {
try {
final combinedFormat = DateFormat(
"${widget.dateFormat.pattern} ${widget.timeFormat!.pattern}",
);
final result = combinedFormat.parse(trimmedString);
if (!result.isBefore(kFirstDay) && !result.isAfter(kLastDay)) {
return result;