FormeSpinNumberField constructor

FormeSpinNumberField({
  1. Key? key,
  2. String? name,
  3. double? initialValue = 0,
  4. FormeAsyncValidator<double>? asyncValidator,
  5. Duration? asyncValidatorDebounce,
  6. AutovalidateMode? autovalidateMode,
  7. FormeFieldDecorator<double>? decorator,
  8. bool enabled = true,
  9. FocusNode? focusNode,
  10. FormeFieldInitialized<double>? onInitialized,
  11. FormeFieldSetter<double>? onSaved,
  12. FormeFieldStatusChanged<double>? onStatusChanged,
  13. int? order,
  14. bool quietlyValidate = false,
  15. bool readOnly = false,
  16. bool requestFocusOnUserInteraction = true,
  17. FormeFieldValidationFilter<double>? validationFilter,
  18. FormeValidator<double>? validator,
  19. bool strictStep = false,
  20. Duration interval = const Duration(milliseconds: 100),
  21. double step = 1,
  22. double acceleration = 0,
  23. required double max,
  24. required double min,
  25. IconConfiguration? increasementIconConfiguration,
  26. IconConfiguration? decreasementIconConfiguration,
  27. bool editable = true,
  28. InputDecoration? decoration = const InputDecoration(),
  29. int? maxLines = 1,
  30. bool autofocus = false,
  31. int? minLines,
  32. int? maxLength,
  33. TextStyle? style,
  34. TextInputAction? textInputAction,
  35. TextCapitalization textCapitalization = TextCapitalization.none,
  36. StrutStyle? strutStyle,
  37. TextAlignVertical? textAlignVertical,
  38. TextDirection? textDirection,
  39. bool? showCursor,
  40. SmartDashesType? smartDashesType,
  41. SmartQuotesType? smartQuotesType,
  42. bool expands = false,
  43. MaxLengthEnforcement? maxLengthEnforcement,
  44. double cursorWidth = 2.0,
  45. double? cursorHeight,
  46. Radius? cursorRadius,
  47. Color? cursorColor,
  48. BoxHeightStyle selectionHeightStyle = BoxHeightStyle.tight,
  49. BoxWidthStyle selectionWidthStyle = BoxWidthStyle.tight,
  50. Brightness? keyboardAppearance,
  51. EdgeInsets scrollPadding = const EdgeInsets.all(20),
  52. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  53. MouseCursor? mouseCursor,
  54. ScrollPhysics? scrollPhysics,
  55. bool enableInteractiveSelection = true,
  56. VoidCallback? onEditingComplete,
  57. List<TextInputFormatter>? inputFormatters,
  58. AppPrivateCommandCallback? appPrivateCommandCallback,
  59. GestureTapCallback? onTap,
  60. ValueChanged<double>? onSubmitted,
  61. ScrollController? scrollController,
  62. TextSelectionControls? textSelectionControls,
  63. TapRegionCallback? onTapOutside,
  64. Clip? clipBehavior,
  65. bool? scribbleEnabled,
  66. EditableTextContextMenuBuilder? contextMenuBuilder = _defaultContextMenuBuilder,
  67. SpellCheckConfiguration? spellCheckConfiguration,
  68. TextMagnifierConfiguration? magnifierConfiguration,
})

Implementation

FormeSpinNumberField({
  super.key,
  super.name,
  double? initialValue = 0,
  super.asyncValidator,
  super.asyncValidatorDebounce,
  super.autovalidateMode,
  super.decorator,
  super.enabled = true,
  super.focusNode,
  super.onInitialized,
  super.onSaved,
  super.onStatusChanged,
  super.order,
  super.quietlyValidate = false,
  super.readOnly = false,
  super.requestFocusOnUserInteraction = true,
  super.validationFilter,
  super.validator,
  this.strictStep = false,
  this.interval = const Duration(milliseconds: 100),
  this.step = 1,
  this.acceleration = 0,
  required this.max,
  required this.min,
  this.increasementIconConfiguration,
  this.decreasementIconConfiguration,
  this.editable = true,
  this.decoration = const InputDecoration(),
  this.maxLines = 1,
  this.autofocus = false,
  this.minLines,
  this.maxLength,
  this.style,
  this.textInputAction,
  this.textCapitalization = TextCapitalization.none,
  this.strutStyle,
  this.textAlignVertical,
  this.textDirection,
  this.showCursor,
  this.smartDashesType,
  this.smartQuotesType,
  this.expands = false,
  this.maxLengthEnforcement,
  this.cursorWidth = 2.0,
  this.cursorHeight,
  this.cursorRadius,
  this.cursorColor,
  this.selectionHeightStyle = BoxHeightStyle.tight,
  this.selectionWidthStyle = BoxWidthStyle.tight,
  this.keyboardAppearance,
  this.scrollPadding = const EdgeInsets.all(20),
  this.dragStartBehavior = DragStartBehavior.start,
  this.mouseCursor,
  this.scrollPhysics,
  this.enableInteractiveSelection = true,
  this.onEditingComplete,
  this.inputFormatters,
  this.appPrivateCommandCallback,
  this.onTap,
  this.onSubmitted,
  this.scrollController,
  this.textSelectionControls,
  this.onTapOutside,
  this.clipBehavior,
  this.scribbleEnabled,
  this.contextMenuBuilder = _defaultContextMenuBuilder,
  this.spellCheckConfiguration,
  this.magnifierConfiguration,
}) : super.allFields(
        initialValue: initialValue == null
            ? min
            : initialValue < min || initialValue > max
                ? min
                : initialValue,
        builder: (baseState) {
          final bool readOnly = baseState.readOnly;
          final bool enabled = baseState.enabled;

          final _FormeSpinNumberFieldState state =
              baseState as _FormeSpinNumberFieldState;

          final InputDecoration finalDecoration =
              (decoration ?? const InputDecoration()).copyWith(
            errorText: state.errorText,
            prefixIcon: IconButton(
              iconSize: decreasementIconConfiguration?.iconSize ?? 24,
              visualDensity: decreasementIconConfiguration?.visualDensity,
              padding: decreasementIconConfiguration?.padding ??
                  const EdgeInsets.all(8.0),
              alignment: decreasementIconConfiguration?.alignment ??
                  Alignment.center,
              splashRadius: decreasementIconConfiguration?.splashRadius,
              color: decreasementIconConfiguration?.color,
              focusColor: decreasementIconConfiguration?.focusColor,
              hoverColor: decreasementIconConfiguration?.hoverColor,
              highlightColor: decreasementIconConfiguration?.highlightColor,
              splashColor: decreasementIconConfiguration?.splashColor,
              disabledColor: decreasementIconConfiguration?.disabledColor,
              tooltip: decreasementIconConfiguration?.tooltip,
              enableFeedback:
                  decreasementIconConfiguration?.enableFeedback ?? true,
              constraints: decreasementIconConfiguration?.constraints,
              onPressed: readOnly ? null : state.subtract,
              icon: GestureDetector(
                onLongPress: readOnly
                    ? null
                    : () {
                        state.startAccelerate(_CalcType.subtract);
                      },
                onLongPressUp: state.stopAccelerate,
                child: decreasementIconConfiguration?.icon ??
                    const Icon(Icons.remove),
              ),
            ),
            suffixIcon: IconButton(
              iconSize: increasementIconConfiguration?.iconSize ?? 24,
              visualDensity: increasementIconConfiguration?.visualDensity,
              padding: increasementIconConfiguration?.padding ??
                  const EdgeInsets.all(8.0),
              alignment: increasementIconConfiguration?.alignment ??
                  Alignment.center,
              splashRadius: increasementIconConfiguration?.splashRadius,
              color: increasementIconConfiguration?.color,
              focusColor: increasementIconConfiguration?.focusColor,
              hoverColor: increasementIconConfiguration?.hoverColor,
              highlightColor: increasementIconConfiguration?.highlightColor,
              splashColor: increasementIconConfiguration?.splashColor,
              disabledColor: increasementIconConfiguration?.disabledColor,
              tooltip: increasementIconConfiguration?.tooltip,
              enableFeedback:
                  increasementIconConfiguration?.enableFeedback ?? true,
              constraints: increasementIconConfiguration?.constraints,
              onPressed: readOnly ? null : state.add,
              icon: GestureDetector(
                onLongPress: readOnly
                    ? null
                    : () {
                        state.startAccelerate(_CalcType.plus);
                      },
                onLongPressUp: state.stopAccelerate,
                child: increasementIconConfiguration?.icon ??
                    const Icon(Icons.add),
              ),
            ),
          );

          return TextField(
            decoration: finalDecoration,
            inputFormatters: state.numberFormatters(
                decimal: state.decimal,
                allowNegative: min < 0,
                max: max.toDouble()),
            controller: state.textEditingController,
            focusNode: state.focusNode,
            onSubmitted: readOnly
                ? null
                : (v) {
                    onSubmitted?.call(state.value);
                  },
            enabled: enabled,
            readOnly: !editable || readOnly,
            onChanged: state.onTextFieldChange,
            textAlign: TextAlign.center,
            onTapOutside: onTapOutside,
            clipBehavior: clipBehavior ?? Clip.hardEdge,
            scribbleEnabled: scribbleEnabled ?? true,
            contextMenuBuilder: contextMenuBuilder,
            spellCheckConfiguration: spellCheckConfiguration,
            magnifierConfiguration: magnifierConfiguration ??
                TextMagnifier.adaptiveMagnifierConfiguration,
            maxLines: maxLines,
            minLines: minLines,
            onTap: onTap,
            onEditingComplete: onEditingComplete,
            onAppPrivateCommand: appPrivateCommandCallback,
            textInputAction: textInputAction,
            textCapitalization: textCapitalization,
            style: style,
            strutStyle: strutStyle,
            textAlignVertical: textAlignVertical,
            textDirection: textDirection,
            showCursor: showCursor,
            smartDashesType: smartDashesType,
            smartQuotesType: smartQuotesType,
            expands: expands,
            cursorWidth: cursorWidth,
            cursorHeight: cursorHeight,
            cursorRadius: cursorRadius,
            cursorColor: cursorColor,
            selectionHeightStyle: selectionHeightStyle,
            selectionWidthStyle: selectionWidthStyle,
            keyboardAppearance: keyboardAppearance,
            scrollPadding: scrollPadding,
            dragStartBehavior: dragStartBehavior,
            mouseCursor: mouseCursor,
            scrollPhysics: scrollPhysics,
            autofocus: autofocus,
            enableInteractiveSelection: enableInteractiveSelection,
            maxLengthEnforcement: maxLengthEnforcement,
            keyboardType: TextInputType.number,
            maxLength: maxLength,
            scrollController: scrollController,
            selectionControls: textSelectionControls,
          );
        },
      );