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 void Function(String?) validator;
  final void Function(String) onChanged;
  final String hintValue;
  WidgetTextFormFieldNumber(
      {required this.textController, required this.onSaved, required this.hintValue, required this.validator, required this.onChanged});
  @override
  Widget build(BuildContext context) {
    return TextFormField(
      keyboardType: const TextInputType.numberWithOptions(decimal: true),
      inputFormatters: [
        FilteringTextInputFormatter.allow(ConstCommon.regExpDecimal),
        ThousandsFormatter(allowFraction: true),
      ],
      decoration: InputDecoration(
        labelText: hintValue,
      ),
      validator: (v) {
        validator(v);
      },
      controller: textController,
      onSaved: (v) {
        onSaved(v);
      },
      onChanged: onChanged,
    );
  }
}
