Is there a way for InputFormatters on a TextFormField to be executed when the form is initially displayed?

You can create a static method to validate your initialValue

class MyFormater extends TextInputFormatter {
  static String defaultFormat(String text) {
    // Do whatever you want
    return text;
  }

  @override
  TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
    // Your validations/formats
    return null;
  }
}

and then you can use it as so

TextFormField(
            initialValue: MyFormater.defaultFormat(someString),
            inputFormatters: [MyFormater()],
          )

I doubt there is other way that will trigger the TextInputFormatter before it has any focus. That initialValue is mean to be already validated and work as a placeholder.

Tags:

Flutter