FormeDateTimeField constructor

FormeDateTimeField({
  1. DateTime? initialValue,
  2. FormeDateTimeType type = FormeDateTimeType.date,
  3. DateTime? firstDate,
  4. DateTime? lastDate,
  5. FormeDateTimeFormatter? formatter,
  6. required String name,
  7. bool readOnly = false,
  8. Key? key,
  9. InputDecoration? decoration,
  10. int? maxLines = 1,
  11. int? order,
  12. bool quietlyValidate = false,
  13. bool autofocus = false,
  14. int? minLines,
  15. int? maxLength,
  16. TextStyle? style,
  17. ToolbarOptions? toolbarOptions,
  18. TextInputAction? textInputAction,
  19. TextCapitalization textCapitalization = TextCapitalization.none,
  20. bool obscureText = false,
  21. StrutStyle? strutStyle,
  22. TextAlign textAlign = TextAlign.start,
  23. TextAlignVertical? textAlignVertical,
  24. TextDirection? textDirection,
  25. bool? showCursor,
  26. String obscuringCharacter = '•',
  27. bool autocorrect = true,
  28. SmartDashesType? smartDashesType,
  29. SmartQuotesType? smartQuotesType,
  30. bool enableSuggestions = true,
  31. bool expands = false,
  32. MaxLengthEnforcement? maxLengthEnforcement,
  33. double cursorWidth = 2.0,
  34. double? cursorHeight,
  35. Radius? cursorRadius,
  36. Color? cursorColor,
  37. BoxHeightStyle selectionHeightStyle = BoxHeightStyle.tight,
  38. BoxWidthStyle selectionWidthStyle = BoxWidthStyle.tight,
  39. Brightness? keyboardAppearance,
  40. EdgeInsets scrollPadding = const EdgeInsets.all(20),
  41. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  42. MouseCursor? mouseCursor,
  43. ScrollPhysics? scrollPhysics,
  44. Iterable<String>? autofillHints,
  45. bool enableInteractiveSelection = true,
  46. bool enabled = true,
  47. VoidCallback? onEditingComplete,
  48. AppPrivateCommandCallback? appPrivateCommandCallback,
  49. InputCounterWidgetBuilder? buildCounter,
  50. ValueChanged<DateTime?>? onSubmitted,
  51. ScrollController? scrollController,
  52. TextSelectionControls? textSelectionControls,
  53. Duration? asyncValidatorDebounce,
  54. AutovalidateMode? autovalidateMode,
  55. FormeFieldStatusChanged<DateTime?>? onStatusChanged,
  56. dynamic onInitialed,
  57. FormeFieldSetter<DateTime?>? onSaved,
  58. FormeValidator<DateTime?>? validator,
  59. FormeAsyncValidator<DateTime?>? asyncValidator,
  60. String? helpText,
  61. String? cancelText,
  62. String? confirmText,
  63. RouteSettings? routeSettings,
  64. DatePickerMode? initialDatePickerMode,
  65. String? errorFormatText,
  66. String? errorInvalidText,
  67. String? fieldHintText,
  68. String? fieldLabelText,
  69. TimePickerEntryMode? initialEntryMode,
  70. DatePickerEntryMode? dateInitialEntryMode,
  71. String? timeCancelText,
  72. String? timeConfirmText,
  73. String? timeHelpText,
  74. RouteSettings? timeRouteSettings,
  75. SelectableDayPredicate? selectableDayPredicate,
  76. TransitionBuilder? builder,
  77. bool use24hFormat = false,
  78. FormeFieldDecorator<DateTime?>? decorator,
  79. bool registrable = true,
  80. TransitionBuilder? timePickerBuilder,
  81. dynamic valueUpdater,
  82. FormeFieldValidationFilter<DateTime?>? validationFilter,
  83. FocusNode? focusNode,
})

Implementation

FormeDateTimeField({
  DateTime? initialValue,
  this.type = FormeDateTimeType.date,
  this.firstDate,
  this.lastDate,
  this.formatter,
  required String name,
  bool readOnly = false,
  Key? key,
  InputDecoration? decoration,
  int? maxLines = 1,
  int? order,
  bool quietlyValidate = false,
  bool autofocus = false,
  int? minLines,
  int? maxLength,
  TextStyle? style,
  ToolbarOptions? toolbarOptions,
  TextInputAction? textInputAction,
  TextCapitalization textCapitalization = TextCapitalization.none,
  bool obscureText = false,
  StrutStyle? strutStyle,
  TextAlign textAlign = TextAlign.start,
  TextAlignVertical? textAlignVertical,
  TextDirection? textDirection,
  bool? showCursor,
  String obscuringCharacter = '•',
  bool autocorrect = true,
  SmartDashesType? smartDashesType,
  SmartQuotesType? smartQuotesType,
  bool enableSuggestions = true,
  bool expands = false,
  MaxLengthEnforcement? maxLengthEnforcement,
  double cursorWidth = 2.0,
  double? cursorHeight,
  Radius? cursorRadius,
  Color? cursorColor,
  BoxHeightStyle selectionHeightStyle = BoxHeightStyle.tight,
  BoxWidthStyle selectionWidthStyle = BoxWidthStyle.tight,
  Brightness? keyboardAppearance,
  EdgeInsets scrollPadding = const EdgeInsets.all(20),
  DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  MouseCursor? mouseCursor,
  ScrollPhysics? scrollPhysics,
  Iterable<String>? autofillHints,
  bool enableInteractiveSelection = true,
  bool enabled = true,
  VoidCallback? onEditingComplete,
  AppPrivateCommandCallback? appPrivateCommandCallback,
  InputCounterWidgetBuilder? buildCounter,
  ValueChanged<DateTime?>? onSubmitted,
  ScrollController? scrollController,
  TextSelectionControls? textSelectionControls,
  Duration? asyncValidatorDebounce,
  AutovalidateMode? autovalidateMode,
  FormeFieldStatusChanged<DateTime?>? onStatusChanged,
  FormeFieldInitialed<DateTime?>? onInitialed,
  FormeFieldSetter<DateTime?>? onSaved,
  FormeValidator<DateTime?>? validator,
  FormeAsyncValidator<DateTime?>? asyncValidator,
  String? helpText,
  String? cancelText,
  String? confirmText,
  RouteSettings? routeSettings,
  DatePickerMode? initialDatePickerMode,
  String? errorFormatText,
  String? errorInvalidText,
  String? fieldHintText,
  String? fieldLabelText,
  TimePickerEntryMode? initialEntryMode,
  DatePickerEntryMode? dateInitialEntryMode,
  String? timeCancelText,
  String? timeConfirmText,
  String? timeHelpText,
  RouteSettings? timeRouteSettings,
  SelectableDayPredicate? selectableDayPredicate,
  TransitionBuilder? builder,

  /// will not work if timePickerBuilder not null
  bool use24hFormat = false,
  FormeFieldDecorator<DateTime?>? decorator,
  bool registrable = true,
  TransitionBuilder? timePickerBuilder,
  FormeFieldValueUpdater<DateTime?>? valueUpdater,
  FormeFieldValidationFilter<DateTime?>? validationFilter,
  FocusNode? focusNode,
}) : super(
        focusNode: focusNode,
        validationFilter: validationFilter,
        valueUpdater: valueUpdater,
        enabled: enabled,
        registrable: registrable,
        decorator: decorator,
        order: order,
        quietlyValidate: quietlyValidate,
        asyncValidatorDebounce: asyncValidatorDebounce,
        autovalidateMode: autovalidateMode,
        onStatusChanged: onStatusChanged,
        onInitialed: onInitialed,
        onSaved: onSaved,
        validator: validator,
        asyncValidator: asyncValidator,
        key: key,
        name: name,
        readOnly: readOnly,
        initialValue: initialValue,
        builder: (baseState) {
          final readOnly = baseState.readOnly;
          final bool enabled = baseState.enabled;
          final state = baseState as _FormeDateTimeFieldState;
          final _firstDate = firstDate ?? DateTime(1970);
          final _lastDate = lastDate ?? DateTime(2099);

          void pickTime() {
            final value = state.initialDateTime;
            final timeOfDay = state.value == null
                ? null
                : TimeOfDay(hour: value.hour, minute: value.minute);

            showDatePicker(
              context: state.context,
              initialDate: value,
              firstDate: _firstDate,
              lastDate: _lastDate,
              helpText: helpText,
              cancelText: cancelText,
              confirmText: confirmText,
              routeSettings: routeSettings,
              textDirection: textDirection,
              initialDatePickerMode:
                  initialDatePickerMode ?? DatePickerMode.day,
              errorFormatText: errorFormatText,
              errorInvalidText: errorInvalidText,
              fieldHintText: fieldHintText,
              fieldLabelText: fieldLabelText,
              initialEntryMode:
                  dateInitialEntryMode ?? DatePickerEntryMode.calendar,
              selectableDayPredicate: selectableDayPredicate,
              builder: builder,
            ).then((date) {
              if (date != null) {
                if (type == FormeDateTimeType.dateTime) {
                  showTimePicker(
                          initialEntryMode:
                              initialEntryMode ?? TimePickerEntryMode.dial,
                          cancelText: timeCancelText,
                          confirmText: timeConfirmText,
                          helpText: timeHelpText,
                          routeSettings: timeRouteSettings,
                          context: state.context,
                          initialTime: timeOfDay ??
                              TimeOfDay(
                                  hour: value.hour, minute: value.minute),
                          builder: timePickerBuilder ??
                              (context, child) {
                                return MediaQuery(
                                  data: MediaQuery.of(context).copyWith(
                                      alwaysUse24HourFormat: use24hFormat),
                                  child: child!,
                                );
                              })
                      .then((value) {
                    if (value != null) {
                      final dateTime = DateTime(date.year, date.month,
                          date.day, value.hour, value.minute);
                      state.didChange(dateTime);
                    }
                  });
                } else {
                  state.didChange(date);
                }
              }
              state.focusNode.requestFocus();
            });
          }

          return TextField(
            focusNode: state.focusNode,
            controller: state.textEditingController,
            decoration: decoration?.copyWith(errorText: state.errorText),
            obscureText: obscureText,
            maxLines: maxLines,
            minLines: minLines,
            enabled: enabled,
            readOnly: true,
            onTap: readOnly ? null : pickTime,
            onEditingComplete: onEditingComplete,
            onSubmitted:
                onSubmitted == null ? null : (v) => onSubmitted(state.value),
            onAppPrivateCommand: appPrivateCommandCallback,
            textInputAction: textInputAction,
            textCapitalization: textCapitalization,
            style: style,
            strutStyle: strutStyle,
            textAlign: textAlign,
            textAlignVertical: textAlignVertical,
            textDirection: textDirection,
            showCursor: showCursor,
            obscuringCharacter: obscuringCharacter,
            autocorrect: autocorrect,
            smartDashesType: smartDashesType,
            smartQuotesType: smartQuotesType,
            enableSuggestions: enableSuggestions,
            expands: expands,
            cursorWidth: cursorWidth,
            cursorHeight: cursorHeight,
            cursorRadius: cursorRadius,
            cursorColor: cursorColor,
            selectionHeightStyle: selectionHeightStyle,
            selectionWidthStyle: selectionWidthStyle,
            keyboardAppearance: keyboardAppearance,
            scrollPadding: scrollPadding,
            dragStartBehavior: dragStartBehavior,
            mouseCursor: mouseCursor,
            scrollPhysics: scrollPhysics,
            autofillHints: readOnly ? null : autofillHints,
            autofocus: autofocus,
            toolbarOptions: toolbarOptions,
            enableInteractiveSelection: enableInteractiveSelection,
            buildCounter: buildCounter,
            maxLengthEnforcement: maxLengthEnforcement,
            maxLength: maxLength,
            scrollController: scrollController,
            selectionControls: textSelectionControls,
          );
        },
      );