I am trying to learn how to use the TextField properly with the MaskTextInputFormatter. I am also using a controller to set a initial value to it. But when the user presses the backspace on it all the text is deleted instead of only 1 char.
Does someone have any ideia of how setting it correctly? I have also tried to change the "selection" property through the controller but nothing changed.
Stateful:
// This sets the initial text into the TextField
class _ErrosState extends State<Erros>
{
var valorController = TextEditingController(
text: "(91) 12345-1234");
// __________________________________________________
// StateLess
class CadastroTelefonePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Scaffold(
body:
TextField(
controller: _ErrosState().valorController,
inputFormatters: [MaskTextInputFormatter(
mask: '(##) #####-####',
filter: {"#": RegExp(r'[0-9 ]')})
],
onChanged: (text) {
_ErrosState.input = text;
},
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: '(XX) XXXXX-XXXX',
),
),
),