EditDouble method
Widget
EditDouble({
- required String name,
- Key? key,
- double? initialValue,
- double? minValue,
- double? maxValue,
- bool signed = true,
- bool allowEmpty = true,
- void onSubmitted()?,
- void onChanged()?,
- String? label,
- String? hint,
- Widget? prefixIcon,
- String? helperText,
- String? errorText,
- int? maxLength,
- bool clear = false,
- Widget? suffixIcon,
- FocusNode? focusNode,
- Color? cursorColor,
- TextInputAction? textInputAction = TextInputAction.next,
- InputDecoration? decoration,
- InputBorder? border,
Implementation
Widget EditDouble({
required String name,
Key? key,
double? initialValue,
double? minValue,
double? maxValue,
bool signed = true,
bool allowEmpty = true,
void Function(String)? onSubmitted,
void Function(String)? onChanged,
String? label,
String? hint,
Widget? prefixIcon,
String? helperText,
String? errorText,
int? maxLength,
bool clear = false,
Widget? suffixIcon,
FocusNode? focusNode,
Color? cursorColor,
TextInputAction? textInputAction = TextInputAction.next,
InputDecoration? decoration,
InputBorder? border,
}) {
_nameControllerMap[name] ??= TextEditingController(text: initialValue?.toString());
_focusMap[name] ??= FocusNode();
return TextFormField(
key: key,
controller: _nameControllerMap[name],
onChanged: onChanged,
onFieldSubmitted: onSubmitted,
focusNode: _focusMap[name],
maxLength: maxLength,
validator: DoubleValidator(minValue: minValue, maxValue: maxValue, allowEmpty: allowEmpty),
keyboardType: TextInputType.numberWithOptions(signed: signed, decimal: true),
textInputAction: textInputAction,
inputFormatters: [signed ? InputFormats.reals : InputFormats.realsUnsigned],
onTapOutside: (e) => _focusMap[name]?.unfocus(),
cursorColor: cursorColor,
decoration:
decoration ??
InputDecoration(
labelText: label,
hintText: hint,
helperText: helperText,
errorText: errorText,
counterText: "",
border: border,
prefixIcon: prefixIcon,
suffixIcon: suffixIcon ?? (!clear ? null : IconButton(icon: Icon(Icons.clear), onPressed: () => _nameControllerMap[name]?.clear())),
),
);
}