EditInt method

Widget EditInt({
  1. required String name,
  2. Key? key,
  3. int? initialValue,
  4. int? minValue,
  5. int? maxValue,
  6. bool signed = true,
  7. bool allowEmpty = true,
  8. void onSubmitted(
    1. String
    )?,
  9. void onChanged(
    1. String
    )?,
  10. String? label,
  11. String? hint,
  12. Widget? prefixIcon,
  13. String? helperText,
  14. String? errorText,
  15. int? maxLength,
  16. bool clear = false,
  17. Widget? suffixIcon,
  18. Color? cursorColor,
  19. TextInputAction? textInputAction = TextInputAction.next,
  20. InputDecoration? decoration,
  21. InputBorder? border,
})

Implementation

Widget EditInt({
  required String name,
  Key? key,
  int? initialValue,
  int? minValue,
  int? 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,
  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: IntValidator(minValue: minValue, maxValue: maxValue, allowEmpty: allowEmpty),
    keyboardType: TextInputType.numberWithOptions(signed: signed, decimal: false),
    inputFormatters: [signed ? InputFormats.reals : InputFormats.realsUnsigned],
    textInputAction: textInputAction,
    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: const Icon(Icons.clear), onPressed: () => _nameControllerMap[name]?.clear())),
        ),
  );
}