import 'package:flutter/services.dart';

class FirstDigitDecimalFormatter extends TextInputFormatter {
  @override
  TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
    String digit = newValue.text.replaceAll(RegExp(r'[^0-9]'), "");
    late String res;

    if (digit.isEmpty) {
      return newValue.copyWith(text: '');
    }

    if (digit.length == 1) {
      res = digit;
    } else {
      res = '${digit[0]}.${digit.substring(1)}';
    }

    return TextEditingValue(
      text: res,
      selection: TextSelection.collapsed(offset: res.length),
    );
  }
}
