import 'package:farm_tpf/utils/const_common.dart';
import 'package:farm_tpf/utils/const_string.dart';
import 'package:farm_tpf/utils/validators.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
import 'package:pattern_formatter/pattern_formatter.dart';

class WidgetTextFormFieldNumber extends StatelessWidget {
  final TextEditingController textController;
  final void Function(String?)? onSaved;
  final String? Function(String?)? validator;
  final void Function(String?)? onChanged;
  final String hintValue;
  final String labelText;
  WidgetTextFormFieldNumber(
      {required this.textController, this.onSaved, required this.hintValue, required this.labelText, this.validator, this.onChanged});
  @override
  Widget build(BuildContext context) {
    return TextFormField(
      keyboardType: TextInputType.numberWithOptions(decimal: true),
      inputFormatters: [
        FilteringTextInputFormatter.allow(ConstCommon.regExpDecimal),
        ThousandsFormatter(allowFraction: true),
      ],
      decoration: InputDecoration(labelText: labelText, hintText: hintValue),
      validator: validator,
      controller: textController,
      onSaved: onSaved,
      onChanged: onChanged,
    );
  }
}
