Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit to change the mask dinamically #9

Merged
merged 3 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/flutter_masked_text.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
library flutter_masked_text;

import 'package:flutter/material.dart';
import 'dart:math';

class MaskedTextController extends TextEditingController {
MaskedTextController({String text, this.mask, Map<String, RegExp> translator})
Expand All @@ -15,14 +14,19 @@ class MaskedTextController extends TextEditingController {
this.updateText(this.text);
}

final String mask;
String mask;

Map<String, RegExp> translator;

void updateText(String text) {
this.text = this._applyMask(this.mask, text);
}

void updateMask(String mask) {
this.mask = mask;
this.updateText(this.text);
}

@override
void set text(String newText) {
if (super.text != newText) {
Expand Down
13 changes: 12 additions & 1 deletion test/flutter_masked_text_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ import 'package:flutter_masked_text/flutter_masked_text.dart';

void main() {
group('masked text', () {
test('12345678901 with mask 000.000.000-00 resunts 123.456.789-01', () {
test('12345678901 with mask 000.000.000-00 results 123.456.789-01', () {
var cpfController =
new MaskedTextController(text: '12345678901', mask: '000.000.000-00');

expect(cpfController.text, '123.456.789-01');
});

test('12345678901 with mask 000.000.000-00 and changed results 123.456.789.01', () {
var cpfController =
new MaskedTextController(text: '12345678901', mask: '000.000.000-00');

expect(cpfController.text, '123.456.789-01');

cpfController.updateMask('000.000.0000-0');

expect(cpfController.text, '123.456.7890-1');
});

test('abc123 with mask AAA results abc', () {
var controller = new MaskedTextController(text: 'abc123', mask: 'AAA');

Expand Down