felixmccuaig / flutter-autocomplete-textfield

An autocomplete Textfield for flutter
MIT License
181 stars 131 forks source link

How to add inputFormatters? #13

Closed john-ravi closed 5 years ago

john-ravi commented 5 years ago
  `AutoCompleteTextField textField;
   ....
   textField.key.currentState.textField.inputFormatters.add(
    WhitelistingTextInputFormatter(RegExp("^[A-Za-z0-9]+");`

This gives null exception. Thank you!

sjmcdowall commented 5 years ago

That's because your example is just DEFINING the variable textField and not CREATING it ..

perhaps something like

AutoCompleteTextField textField = AutoCompleteTextField(arg1, arg2, etc);

textField.key.currentState.textField.inputFormatters.add.... would work? (not sure but at least textField would be initialized

felixmccuaig commented 5 years ago

@john-ravi I'm adding this feature now. :)

felixmccuaig commented 5 years ago

Added inputformatters param in autocomplete_textfield as of 1.6.4.

sjmcdowall commented 5 years ago

@felixlucien -- If not already thought of you may want to follow the pattern of the "other" autocomplete project and allow just about any textfield modification to be passed in via a named parameter..

It's the flutter_typeahead project .. and he uses a TextFieldConfiguration idea as in the following code

TypeAheadField(
  textFieldConfiguration: TextFieldConfiguration(
    autofocus: true,
    style: DefaultTextStyle.of(context).style.copyWith(
      fontStyle: FontStyle.italic
    ),
    decoration: InputDecoration(
      border: OutlineInputBorder()
    )
  ),

There are lot more options obviously but you get the idea (and since it's open source...)

felixmccuaig commented 5 years ago

I may look into doing such a thing. For now, it all seems to work well however it could be useful for simplicity.