mask_text_input_formatter icon indicating copy to clipboard operation
mask_text_input_formatter copied to clipboard

default value has problem

Open MohammadMobasher opened this issue 4 years ago • 2 comments

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";

MohammadMobasher avatar Dec 30 '20 18:12 MohammadMobasher

I also want to know how to start with a correctly value in the mask

EmanoelV avatar Feb 19 '21 20:02 EmanoelV

+1

jacopofranza avatar May 07 '21 18:05 jacopofranza

@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],
      ...
    ),
  ),
}

ehdwns980416 avatar Feb 18 '23 13:02 ehdwns980416