0

Text input should not be space as initial. once user write some charater it allows to put space between two words. but as an initial character it supports only and only text in text form field.

1 Answers1

1

If you want to restrict space as an initial character, you can achieve that by inputFormatters, here's an example:

class NoInitialSpaceInputFormatter extends TextInputFormatter {
  @override
  TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
    // Prevent entering a space as the initial character
    if (newValue.text.startsWith(' ')) {
      return oldValue;
    }
    return newValue;
  }
}

And pass it as a inputFormatters to TextField like this:

TextField(
    inputFormatters: [NoInitialSpaceInputFormatter()],
)