Skip to content

Commit 4629122

Browse files
committed
Cleaner way to fix time picker dialog locale using builder
1 parent 90ccb8c commit 4629122

File tree

1 file changed

+16
-56
lines changed

1 file changed

+16
-56
lines changed

lib/src/fields/form_builder_date_time_picker.dart

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -342,16 +342,29 @@ class _FormBuilderDateTimePickerState
342342

343343
Future<TimeOfDay?> _showTimePicker(
344344
BuildContext context, DateTime? currentValue) async {
345-
final timePickerResult = await showFormBuilderTimePicker(
345+
var builder = widget.transitionBuilder;
346+
if (widget.locale != null) {
347+
builder = (context, child) {
348+
var transitionBuilder = widget.transitionBuilder;
349+
return Localizations.override(
350+
context: context,
351+
locale: widget.locale,
352+
child: transitionBuilder == null
353+
? child
354+
: transitionBuilder(context, child),
355+
);
356+
};
357+
}
358+
359+
final timePickerResult = await showTimePicker(
346360
context: context,
347361
initialTime: currentValue != null
348362
? TimeOfDay.fromDateTime(currentValue)
349363
: widget.initialTime,
350-
builder: widget.transitionBuilder,
364+
builder: builder,
351365
useRootNavigator: widget.useRootNavigator,
352366
routeSettings: widget.routeSettings,
353367
initialEntryMode: widget.timePickerInitialEntryMode,
354-
locale: widget.locale,
355368
helpText: widget.helpText,
356369
confirmText: widget.confirmText,
357370
cancelText: widget.cancelText,
@@ -377,56 +390,3 @@ class _FormBuilderDateTimePickerState
377390
(value == null) ? '' : _dateFormat.format(value);
378391
}
379392
}
380-
381-
Future<TimeOfDay?> showFormBuilderTimePicker({
382-
required BuildContext context,
383-
required TimeOfDay initialTime,
384-
TransitionBuilder? builder,
385-
bool useRootNavigator = true,
386-
TimePickerEntryMode initialEntryMode = TimePickerEntryMode.dial,
387-
Locale? locale,
388-
String? cancelText,
389-
String? confirmText,
390-
String? helpText,
391-
String? errorInvalidText,
392-
String? hourLabelText,
393-
String? minuteLabelText,
394-
RouteSettings? routeSettings,
395-
EntryModeChangeCallback? onEntryModeChanged,
396-
Offset? anchorPoint,
397-
}) async {
398-
assert(context != null);
399-
assert(initialTime != null);
400-
assert(useRootNavigator != null);
401-
assert(initialEntryMode != null);
402-
assert(debugCheckHasMaterialLocalizations(context));
403-
404-
Widget dialog = TimePickerDialog(
405-
initialTime: initialTime,
406-
initialEntryMode: initialEntryMode,
407-
cancelText: cancelText,
408-
confirmText: confirmText,
409-
helpText: helpText,
410-
errorInvalidText: errorInvalidText,
411-
hourLabelText: hourLabelText,
412-
minuteLabelText: minuteLabelText,
413-
onEntryModeChanged: onEntryModeChanged,
414-
);
415-
if (locale != null) {
416-
dialog = Localizations.override(
417-
context: context,
418-
locale: locale,
419-
child: dialog,
420-
);
421-
}
422-
423-
return showDialog<TimeOfDay>(
424-
context: context,
425-
useRootNavigator: useRootNavigator,
426-
builder: (BuildContext context) {
427-
return builder == null ? dialog : builder(context, dialog);
428-
},
429-
routeSettings: routeSettings,
430-
anchorPoint: anchorPoint,
431-
);
432-
}

0 commit comments

Comments
 (0)