TxNumberFormField constructor
TxNumberFormField({
- bool? clearable,
- Key? key,
- FormFieldSetter<
num> ? onSaved, - FormFieldValidator<
num> ? validator, - bool? enabled,
- AutovalidateMode? autovalidateMode = AutovalidateMode.onUserInteraction,
- String? restorationId,
- InputDecoration? decoration,
- ValueChanged<
num?> ? onChanged, - bool? required,
- num? initialValue,
- bool? bordered,
- String? hintText,
- num? maxValue,
- num? minValue,
- bool? stepped,
- num? step,
- int? precision,
- bool? stepStrictly,
- TextEditingController? controller,
- UndoHistoryController? undoController,
- TextInputAction? textInputAction,
- TextCapitalization? textCapitalization,
- TextStyle? style,
- StrutStyle? strutStyle,
- TextAlign? textAlign,
- TextAlignVertical? textAlignVertical,
- TextDirection? textDirection,
- bool? readOnly,
- bool? showCursor,
- bool? autofocus,
- MaterialStatesController? statesController,
- String? obscuringCharacter,
- bool? obscureText,
- bool? autocorrect,
- SmartDashesType? smartDashesType,
- SmartQuotesType? smartQuotesType,
- bool? enableSuggestions,
- int? maxLines,
- int? minLines,
- bool? expands,
- int? maxLength,
- MaxLengthEnforcement? maxLengthEnforcement,
- VoidCallback? onEditingComplete,
- ValueChanged<
String> ? onFieldSubmitted, - AppPrivateCommandCallback? onAppPrivateCommand,
- List<
TextInputFormatter> ? inputFormatters, - double? cursorWidth,
- double? cursorHeight,
- Radius? cursorRadius,
- bool? cursorOpacityAnimates,
- Color? cursorColor,
- Color? cursorErrorColor,
- BoxHeightStyle? selectionHeightStyle,
- BoxWidthStyle? selectionWidthStyle,
- Brightness? keyboardAppearance,
- EdgeInsets? scrollPadding,
- DragStartBehavior? dragStartBehavior,
- bool? enableInteractiveSelection,
- TextSelectionControls? selectionControls,
- GestureTapCallback? onTap,
- bool? onTapAlwaysCalled,
- TapRegionCallback? onTapOutside,
- MouseCursor? mouseCursor,
- InputCounterWidgetBuilder? buildCounter,
- ScrollController? scrollController,
- ScrollPhysics? scrollPhysics,
- Iterable<
String> ? autofillHints, - ContentInsertionConfiguration? contentInsertionConfiguration,
- Clip? clipBehavior,
- bool? scribbleEnabled,
- bool? enableIMEPersonalizedLearning,
- EditableTextContextMenuBuilder? contextMenuBuilder,
- bool? canRequestFocus,
- SpellCheckConfiguration? spellCheckConfiguration,
- TextMagnifierConfiguration? magnifierConfiguration,
- Widget? label,
- String? labelText,
- TextAlign? labelTextAlign,
- TextOverflow? labelOverflow,
- EdgeInsetsGeometry? padding,
- FieldActionsBuilder<
num> ? actionsBuilder, - TextStyle? labelStyle,
- double? horizontalGap,
- Color? tileColor,
- Axis? layoutDirection,
- TxFormFieldBuilder<
num> ? trailingBuilder, - Widget? leading,
- VisualDensity? visualDensity,
- ShapeBorder? shape,
- Color? iconColor,
- Color? textColor,
- TextStyle? leadingAndTrailingTextStyle,
- double? minLeadingWidth,
- double? minLabelWidth,
- double? minVerticalPadding,
- bool? dense,
- ValueChanged<
TxFormFieldState< ? onFieldTap,num> > - bool? colon,
- Color? focusColor,
- FocusNode? focusNode,
Implementation
TxNumberFormField({
bool? clearable,
super.key,
super.onSaved,
FormFieldValidator<num>? validator,
super.enabled,
super.autovalidateMode,
super.restorationId,
super.decoration,
super.onChanged,
super.required,
super.initialValue,
super.bordered,
String? hintText,
this.maxValue,
this.minValue,
bool? stepped,
this.step,
this.precision,
bool? stepStrictly,
super.controller,
super.undoController,
super.textInputAction,
super.textCapitalization,
super.style,
super.strutStyle,
TextAlign? textAlign,
super.textAlignVertical,
super.textDirection,
super.readOnly,
super.showCursor,
super.autofocus,
super.statesController,
super.obscuringCharacter,
super.obscureText,
super.autocorrect,
super.smartDashesType,
super.smartQuotesType,
super.enableSuggestions,
super.maxLines,
super.minLines,
super.expands,
super.maxLength,
super.maxLengthEnforcement,
super.onEditingComplete,
super.onFieldSubmitted,
super.onAppPrivateCommand,
List<TextInputFormatter>? inputFormatters,
super.cursorWidth,
super.cursorHeight,
super.cursorRadius,
super.cursorOpacityAnimates,
super.cursorColor,
super.cursorErrorColor,
super.selectionHeightStyle,
super.selectionWidthStyle,
super.keyboardAppearance,
super.scrollPadding,
super.dragStartBehavior,
super.enableInteractiveSelection,
super.selectionControls,
super.onTap,
super.onTapAlwaysCalled,
super.onTapOutside,
super.mouseCursor,
super.buildCounter,
super.scrollController,
super.scrollPhysics,
super.autofillHints,
super.contentInsertionConfiguration,
super.clipBehavior,
super.scribbleEnabled,
super.enableIMEPersonalizedLearning,
super.contextMenuBuilder,
super.canRequestFocus,
super.spellCheckConfiguration,
super.magnifierConfiguration,
super.label,
super.labelText,
super.labelTextAlign,
super.labelOverflow,
super.padding,
super.actionsBuilder,
super.labelStyle,
super.horizontalGap,
super.tileColor,
super.layoutDirection,
super.trailingBuilder,
super.leading,
super.visualDensity,
super.shape,
super.iconColor,
super.textColor,
super.leadingAndTrailingTextStyle,
super.minLeadingWidth,
super.minLabelWidth,
super.minVerticalPadding,
super.dense,
super.onFieldTap,
super.colon,
super.focusColor,
super.focusNode,
}) : stepped = stepped ?? false,
stepStrictly = stepStrictly ?? false,
super(
hintText: hintText ?? '请输入',
clearable: clearable ?? false,
displayTextMapper: (context, val) => val.toString(),
keyboardType: TextInputType.number,
textAlign: textAlign ?? (stepped == true ? TextAlign.center : null),
onInputChanged: (field, val) {
final num? number = num.tryParse(val);
if (number != field.value) {
(field as TxCommonTextFormFieldState).didChange(number);
}
},
inputFormatters: [
...?inputFormatters,
NumberInputFormatter(
min: minValue,
max: maxValue,
precision: precision,
step: step,
stepStrictly: stepStrictly,
),
],
validator: (value) {
if (required == true && value == null) {
return '请输入';
}
if (validator != null) {
final String? errorText = validator(value);
if (errorText != null) {
return errorText;
}
}
/// 如果最小值不为空,判断输入值是否小于最小值
if (minValue != null && value != null && value < minValue) {
return '输入值需大于或等于$minValue';
}
/// 如果最小数量不为空,判断已选数量是否小于最小数量
if (maxValue != null && value != null && value > maxValue) {
return '输入值需小于或等于$maxValue';
}
return null;
},
);