• Greg Spencer's avatar
    Add Material character counter to TextField. (#12648) · ea679171
    Greg Spencer authored
    This adds an optional character counter and maxLength parameter to the TextField, as described in the Material Design Spec.
    
    The counter text and style in the input decorator may be specified, but will default to the "right thing" if not specified, where the "right thing" is a counter that looks like "3 / 10" (if there are three characters entered into a field where maxLength is set to 10).
    
    To limit the number of characters entered, I created a LengthLimitingTextFormatter that will limit the number of characters (Unicode runes) in the input, which can be used independently. The formatter is applied after the other formatters supplied (if any). Even if there is no decorator, the text field will limit the number of characters input if maxLength is set.
    
    If maxLengthEnforced is set to false (it defaults to true), then the max length will not be enforced. In that case, if the text exceeds the length, then the counter will turn red, and it will make the divider turn red.
    ea679171
text_formatter_test.dart 7.42 KB