Search code examples
fluttertextformfield

Flutter add dash after every 3 number textfield input and limit number of figure input


I'm looking for a way to add ( - ) after every number input in flutter textformfield and to limit the number of input to just 9 figure. For example 145-123-234. I will appreciate if anyone can help with this.


Solution

  • So I install this flutter_masked_text

    And imported the library to my input page, changed my TextFormField controller to MaskedTextController _controllerCode = MaskedTextController(mask: '000-000-000'); then parse _controllerCode to controller in the TextFormField and finally my Widget looks like below:

      MaskedTextController _controller = MaskedTextController(mask: '000-000-000');
    
      @override
      Widget build(BuildContext context) {
        return TextField(
          controller: _controller,
          decoration: InputDecoration(
            hintText: 'e.g. 101-234-190',
          ),
        );
      }
    }```