mask_text_input_formatter
mask_text_input_formatter copied to clipboard
default value has problem
hi and tanks for you'r good library. i added a default value to TextEditController for example => 12:23:59 it works fine, but when i tab on TextField for change the value and press backspace the whole value gone! can you please help me. tanks a lot, this is my code: this.startController.text = "12:23:59";
I also want to know how to start with a correctly value in the mask
+1
@MohammadMobasher @EmanoelV How about this?
/// Formatter
late MaskTextInputFormatter testFormatter;
final mask = "##:##:##";
/// Controller
final TextEditingController _testController = TextEditingController();
@override
void initState() {
super.initState();
...
final initialText = "12:23:59";
testFormatter = MaskTextInputFormatter(
mask: mask,
filter: {"#": RegExp(r'[0-9]')},
type: MaskAutoCompletionType.lazy,
initialText: initialText,
);
_testController.text = initialText;
}
@override
void dispose() {
...
_testController.dispose();
super.dispose();
}
...
@override
Widget build(BuildContext context) {
_testController.value = testFormatter.updateMask(mask: mask);
return Center(
child: TextFormField(
controller: _testController,
inputFormatters: [testFormatter],
...
),
),
}