Flutter Masked Text 2 は、カスタムマスクを使用したフォーマットされたテキスト入力を可能にするFlutterパッケージであり、電話番号、日付、クレジットカードなどのフィールドに最適です。ユーザーが入力する際にリアルタイムで入力検証とフォーマットを提供し、データの一貫性を保証します。Android、iOS、Web、macOS、Windows、Linuxなど複数のプラットフォームをサポートしています。軽量で、簡単に統合でき、入力中にカーソル位置を維持します。パフォーマンスを損なわず、直感的で使いやすい入力処理を求める開発者向けに設計されています。
If you want to use default translator but override some of then, just get base from getDefaultTranslator and override what you want (here is a sample for obfuscated credit card):
var translator = MaskedTextController.getDefaultTranslator(); // get new instance of default translator.
translator.remove('*'); // removing wildcard translator.var controller = newMaskedTextController(mask: '0000 **** **** 0000', translator: translator);
controller.updateText('12345678');
print(controller.text); //1234 **** **** 5678
Change the mask in runtime
You can use the updateMask method to change the mask after the controller was created.
In some cases, you will want to validate the mask value to decide if it's allowed to input or not.
It's simple: you just need to set the beforeChange and return true or false. If you return true, it will accept the new value and will try to apply the mask. Otherwhise, it will reject the new value.
The function receives two parameters:
previous: the previous text of the controller.
next: the next text that will be masked.
var controller = newMaskedTextController(mask: '(00) 0000-0000');
controller.beforeChange = (String previous, String next) {
// my logic herereturntrue;
};
Hook: afterChange [v0.7.0+]
This function will be called after setted in the controller.