diff --git a/.gitignore b/.gitignore
index 446ed0d..b60b215 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,8 +3,10 @@
.packages
.pub/
+.idea
build/
ios/.generated/
ios/Flutter/Generated.xcconfig
ios/Runner/GeneratedPluginRegistrant.*
+
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
deleted file mode 100644
index 30aa626..0000000
--- a/.idea/codeStyles/Project.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml
index d96f80d..a2b8513 100644
--- a/.idea/libraries/Dart_Packages.xml
+++ b/.idea/libraries/Dart_Packages.xml
@@ -2,66 +2,31 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml
deleted file mode 100644
index ff827be..0000000
--- a/.idea/libraries/Dart_SDK.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml
deleted file mode 100644
index b0f6971..0000000
--- a/.idea/libraries/Flutter_Plugins.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index de732b4..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 228130c..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 35eb1dd..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 681cc5a..37fa503 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,7 +2,78 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -20,10 +91,10 @@
-
-
+
+
-
+
@@ -32,22 +103,19 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -55,8 +123,8 @@
-
-
+
+
@@ -66,22 +134,10 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -99,16 +155,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -138,18 +184,20 @@
-
-
+
+
+
+
-
-
+
+
@@ -166,9 +214,6 @@
-
-
-
@@ -181,16 +226,14 @@
-
-
-
-
-
+
+
+
@@ -199,7 +242,7 @@
-
+
@@ -577,8 +620,7 @@
-
-
+
@@ -592,7 +634,7 @@
-
+
@@ -618,12 +660,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -641,7 +740,6 @@
-
@@ -661,19 +759,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -688,20 +774,13 @@
-
-
-
-
-
-
-
-
+
-
+
@@ -711,7 +790,6 @@
-
@@ -731,19 +809,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -758,14 +824,7 @@
-
-
-
-
-
-
-
-
+
@@ -779,7 +838,7 @@
-
+
@@ -800,20 +859,12 @@
-
-
-
-
-
-
-
-
+
-
@@ -824,7 +875,7 @@
-
+
@@ -841,7 +892,6 @@
-
@@ -853,20 +903,13 @@
-
-
-
-
-
-
-
-
+
-
+
@@ -883,7 +926,6 @@
-
@@ -907,7 +949,7 @@
-
+
@@ -959,59 +1001,24 @@
-
-
-
-
-
-
-
-
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -1027,8 +1034,7 @@
-
-
+
@@ -1036,6 +1042,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 909d3b9..4fb0856 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,14 +1,39 @@
+## [0.8.0] - 2019-fev-24
+
+### Added
+
+- Adding `precision` to `MoneyMaskedTextController`.
+
+### Fixed
+
+- Fixing `initialValue` in `MoneyMaskedTextController`.
+- Fixing crash when call `updateText` in `MaskedTextController` with `null` value. (thanks to [Israel Ibarra](https://github.com/ElZombieIsra))
+
+## [0.7.0] - 2018-nov-12
+
+- Adding `beforeChange` and `afterChange` hooks.
+
+## [0.6.0] - 2018-ago-16.
+
+- Now you can change the mask in runtime (thanks to [calebeoliveira](https://github.com/calebeoliveira)).
+- The sdk support is updated to `>=1.23.0 <3.0.0` (thanks to [tobire](https://github.com/tobire)).
+
## [0.5.0] - 2018-jun-17.
-* Adding left and right symbols (thanks to [tobire](https://github.com/tobire)).
+
+- Adding left and right symbols (thanks to [tobire](https://github.com/tobire)).
## [0.4.1] - 2018-jun-11.
-* Fixing not allowed characters on keyboard (thanks to [tobire](https://github.com/tobire)). Related: [issue#3](https://github.com/benhurott/flutter-masked-text/issues/3).
+
+- Fixing not allowed characters on keyboard (thanks to [tobire](https://github.com/tobire)). Related: [issue#3](https://github.com/benhurott/flutter-masked-text/issues/3).
## [0.4.0] - 2018-may-21.
-* Adding money mask.
+
+- Adding money mask.
## [0.3.0] - 2018-may-21.
-* Adding custom translations.
+
+- Adding custom translations.
## [0.2.1] - 2018-may-21.
-* First release.
+
+- First release.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..523ad1e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,5 @@
+validate:
+ flutter test
+
+publish:
+ make validate && flutter packages pub publish
\ No newline at end of file
diff --git a/README.md b/README.md
index 16b4bdc..8132131 100644
--- a/README.md
+++ b/README.md
@@ -6,12 +6,20 @@ Masked text input for flutter.

+## Alert
+
+Hi guys!
+
+Unfortunately, I'm not developing mobile anymore. This repo will not receive updates.
+
## Install
Follow this [GUIDE](https://pub.dartlang.org/packages/flutter_masked_text#-installing-tab-)
## Usage
+
Import the library
+
```dart
import 'package:flutter_masked_text/flutter_masked_text.dart';
```
@@ -19,11 +27,13 @@ import 'package:flutter_masked_text/flutter_masked_text.dart';
## MaskedText
Create your mask controller:
+
```dart
var controller = new MaskedTextController(mask: '000.000.000-00');
```
Set controller to your text field:
+
```dart
return new MaterialApp(
title: 'Flutter Demo',
@@ -46,22 +56,27 @@ This is the result:

-#### Mask Options
+### Mask Options
In mask, you can use the following characters:
-* `0`: accept numbers
-* `A`: accept letters
-* `@`: accept numbers and letters
-* `*`: accept any character
-#### Initial Value
+- `0`: accept numbers
+- `A`: accept letters
+- `@`: accept numbers and letters
+- `*`: accept any character
+
+### Initial Value
+
To start a mask with initial value, just use `text` property on constructor:
+
```dart
var controller = new MaskedTextController(mask: '000-000', text: '123456');
```
-#### Update text programaticaly
+### Update text programaticaly
+
If you want to set new text after controller initiatialization, use the `updateText` method:
+
```dart
var controller = new MaskedTextController(text: '', mask: '000-000');
controller.updateText('123456');
@@ -69,8 +84,10 @@ controller.updateText('123456');
print(controller.text); //123-456
```
-#### Using custom translators
+### Using custom translators
+
If you want to use your custom regex to allow values, you can pass a custom translation dictionary:
+
```dart
const translator = {
'#': new RegExp(r'my regex here')
@@ -80,6 +97,7 @@ var controller = new MaskedTextController(mask: '####', translator: translator);
```
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):
+
```dart
var translator = MaskedTextController.getDefaultTranslator(); // get new instance of default translator.
translator.remove('*'); // removing wildcard translator.
@@ -90,8 +108,60 @@ 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.
+
+```dart
+var cpfController = new MaskedTextController(text: '12345678901', mask: '000.000.000-00');
+
+print(cpfController.text); //'123.456.789-01'
+
+cpfController.updateMask('000.000.0000-0');
+
+print(cpfController.text); //'123.456.7890-1'
+```
+
+### Hook: beforeChange [v0.7.0+]
+
+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.
+
+```dart
+var controller = new MaskedTextController(mask: '(00) 0000-0000');
+controller.beforeChange = (String previous, String next) {
+ // my logic here
+
+ return true;
+};
+```
+
+### Hook: afterChange [v0.7.0+]
+
+This function will be called after setted in the controller.
+
+The function receives two parameters:
+
+- `previous`: the previous text of the controller.
+- `next`: the next text that will be masked.
+
+```dart
+var controller = new MaskedTextController(mask: '(00) 0000-0000');
+controller.afterChange = (String previous, String next) {
+ print("$previous | $next");
+};
+```
+
## Money Mask
+
To use money mask, create a MoneyMaskedTextController:
+
```dart
var controller = new MoneyMaskedTextController();
@@ -99,32 +169,34 @@ var controller = new MoneyMaskedTextController();
new TextField(controller: controller, keyboardType: TextInputType.number)
```
-#### Decimal and Thousand separator
+### Decimal and Thousand separator
It's possible to customize `decimal` and `thousand` separators:
+
```dart
var controller = new MoneyMaskedTextController(decimalSeparator: '.', thousandSeparator: ',');
```
-#### Set value programaticaly
+### Set value programaticaly
To set value programaticaly, use `updateValue`:
+
```dart
controller.updateValue(1234.0);
```
-
-#### Get double value
+### Get double value
To get the number value from masked text, use the `numberValue` property:
+
```dart
double val = controller.numberValue;
```
-
-#### Using decoration symbols
+### Using decoration symbols
You can use currency symbols if you want:
+
```dart
// left symbol
var controller = new MoneyMaskedTextController(leftSymbol: 'R\$ ');
@@ -147,11 +219,44 @@ controller.updateValue(123.45);
print(controller.text); //<-- to pay: 123,45 US$
```
+### hook: afterChange [v0.7.0+]
+
+You can watch for mask and value changes. To do this, just set the `afterChange` hook.
+
+This function receives two parameters:
+
+- `masked`: the masked text of the controller.
+- `raw`: the double value of the text.
+
+```dart
+var controller = new MoneyMaskedTextController();
+
+controller.afterChange = (String masked, double raw) {
+ print("$masked | $raw");
+};
+```
+
+### Defining decimal places [v0.8.0+]
+
+You can define the number of decimal places using the `precision` prop:
+
+```dart
+var controller = new MoneyMaskedTextController(precision: 3);
+controller.updateValue(123.45);
+
+print(controller.text); //<-- 123,450
+```
+
## Using default TextEditingController
+
The MaskedTextController and MoneyMaskedTextController extends TextEditingController. You can use all default native methods from this class.
+## Samples
+
+You can check some code samples in this repo: [flutter-masked-text-samples](https://github.com/benhurott/flutter-masked-text-samples)
+
## TODO
-- [x] Custom translations
-- [x] Money Mask
-- [ ] Raw Text Widget
-- [ ] Default Pre-Sets like CPF, CNPJ, Date, Credit Card, etc...
+
+- [x] Custom translations
+- [x] Money Mask
+- [ ] Raw Text Widget
diff --git a/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java b/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
new file mode 100644
index 0000000..d007606
--- /dev/null
+++ b/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
@@ -0,0 +1,23 @@
+package io.flutter.plugins;
+
+import io.flutter.plugin.common.PluginRegistry;
+
+/**
+ * Generated file. Do not edit.
+ */
+public final class GeneratedPluginRegistrant {
+ public static void registerWith(PluginRegistry registry) {
+ if (alreadyRegisteredWith(registry)) {
+ return;
+ }
+ }
+
+ private static boolean alreadyRegisteredWith(PluginRegistry registry) {
+ final String key = GeneratedPluginRegistrant.class.getCanonicalName();
+ if (registry.hasPlugin(key)) {
+ return true;
+ }
+ registry.registrarFor(key);
+ return false;
+ }
+}
diff --git a/android/local.properties b/android/local.properties
new file mode 100644
index 0000000..fae3c9c
--- /dev/null
+++ b/android/local.properties
@@ -0,0 +1,2 @@
+sdk.dir=/Users/ben/Library/Android/sdk
+flutter.sdk=/Users/ben/Documents/dev/flutter
\ No newline at end of file
diff --git a/flutter_masked_text.iml b/flutter_masked_text.iml
index d9bd5ad..304065a 100644
--- a/flutter_masked_text.iml
+++ b/flutter_masked_text.iml
@@ -9,6 +9,9 @@
+
+
+
diff --git a/lib/flutter_masked_text.dart b/lib/flutter_masked_text.dart
index 4a08b79..e75adf9 100644
--- a/lib/flutter_masked_text.dart
+++ b/lib/flutter_masked_text.dart
@@ -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 translator})
@@ -9,26 +8,60 @@ class MaskedTextController extends TextEditingController {
this.translator = translator ?? MaskedTextController.getDefaultTranslator();
this.addListener(() {
- this.updateText(this.text);
+ var previous = this._lastUpdatedText;
+ if (this.beforeChange(previous, this.text)) {
+ this.updateText(this.text);
+ this.afterChange(previous, this.text);
+ } else {
+ this.updateText(this._lastUpdatedText);
+ }
});
this.updateText(this.text);
}
- final String mask;
+ String mask;
Map translator;
+ Function afterChange = (String previous, String next) {};
+ Function beforeChange = (String previous, String next) {
+ return true;
+ };
+
+ String _lastUpdatedText = '';
+
void updateText(String text) {
- this.text = this._applyMask(this.mask, text);
+ if(text != null){
+ this.text = this._applyMask(this.mask, text);
+ }
+ else {
+ this.text = '';
+ }
+
+ this._lastUpdatedText = this.text;
+ }
+
+ void updateMask(String mask, {bool moveCursorToEnd = true}) {
+ this.mask = mask;
+ this.updateText(this.text);
+
+ if (moveCursorToEnd) {
+ this.moveCursorToEnd();
+ }
+ }
+
+ void moveCursorToEnd() {
+ var text = this._lastUpdatedText;
+ this.selection = new TextSelection.fromPosition(
+ new TextPosition(offset: (text ?? '').length));
}
@override
void set text(String newText) {
if (super.text != newText) {
super.text = newText;
- this.selection = new TextSelection.fromPosition(
- new TextPosition(offset: (newText ?? '').length));
+ this.moveCursorToEnd();
}
}
@@ -99,11 +132,13 @@ class MoneyMaskedTextController extends TextEditingController {
this.decimalSeparator = ',',
this.thousandSeparator = '.',
this.rightSymbol = '',
- this.leftSymbol = ''}) {
+ this.leftSymbol = '',
+ this.precision = 2}) {
_validateConfig();
this.addListener(() {
this.updateValue(this.numberValue);
+ this.afterChange(this.text, this.numberValue);
});
this.updateValue(initialValue);
@@ -113,17 +148,24 @@ class MoneyMaskedTextController extends TextEditingController {
final String thousandSeparator;
final String rightSymbol;
final String leftSymbol;
+ final int precision;
- // this is the maximum supported for double values.
- final int _maxLength = 19;
+ Function afterChange = (String maskedValue, double rawValue) {};
+
+ double _lastValue = 0.0;
void updateValue(double value) {
- String masked = this._applyMask(value);
+ double valueToUse = value;
- if (masked.length > _maxLength) {
- masked = masked.substring(0, _maxLength);
+ if (value.toStringAsFixed(0).length > 12) {
+ valueToUse = _lastValue;
+ }
+ else {
+ _lastValue = value;
}
+ String masked = this._applyMask(valueToUse);
+
if (rightSymbol.length > 0) {
masked += rightSymbol;
}
@@ -141,25 +183,13 @@ class MoneyMaskedTextController extends TextEditingController {
}
}
- double get numberValue => double.parse(_getSanitizedText(this.text)) / 100.0;
-
-// @override
-// set text(String newText) {
-// String formattedText = "";
-//
-// if (newText.length <= _maxLengthForNumbers) {
-// formattedText = newText;
-// } else {
-// formattedText = newText.substring(0, _maxLengthForNumbers);
-// }
-//
-// super.text = formattedText + "${this.rightSymbol}";
-//
-// var cursorPosition = super.text.length - this.rightSymbol.length;
-//
-// this.selection = new TextSelection.fromPosition(
-// new TextPosition(offset: cursorPosition));
-// }
+ double get numberValue {
+ List parts = _getOnlyNumbers(this.text).split('').toList(growable: true);
+
+ parts.insert(parts.length - precision, '.');
+
+ return double.parse(parts.join());
+ }
_validateConfig() {
bool rightSymbolHasNumbers = _getOnlyNumbers(this.rightSymbol).length > 0;
@@ -169,20 +199,6 @@ class MoneyMaskedTextController extends TextEditingController {
}
}
- String _getSanitizedText(String text) {
- String cleanedText = text;
-
- var valuesToSanitize = [this.thousandSeparator, this.decimalSeparator];
-
- valuesToSanitize.forEach((val) {
- cleanedText = cleanedText.replaceAll(val, '');
- });
-
- cleanedText = _getOnlyNumbers(cleanedText);
-
- return cleanedText;
- }
-
String _getOnlyNumbers(String text) {
String cleanedText = text;
@@ -194,29 +210,23 @@ class MoneyMaskedTextController extends TextEditingController {
}
String _applyMask(double value) {
- String textRepresentation =
- value.toStringAsFixed(2).replaceAll('.', this.decimalSeparator);
-
- List numberParts = [];
-
- for (var i = 0; i < textRepresentation.length; i++) {
- numberParts.add(textRepresentation[i]);
- }
+ List textRepresentation = value.toStringAsFixed(precision)
+ .replaceAll('.', '')
+ .split('')
+ .reversed
+ .toList(growable: true);
- const lengthsWithThousandSeparators = [6, 10, 14, 18];
+ textRepresentation.insert(precision, decimalSeparator);
- for (var i = 0; i < lengthsWithThousandSeparators.length; i++) {
- var l = lengthsWithThousandSeparators[i];
-
- if (numberParts.length > l) {
- numberParts.insert(numberParts.length - l, this.thousandSeparator);
- } else {
+ for (var i = precision + 4; true; i = i + 4) {
+ if (textRepresentation.length > i) {
+ textRepresentation.insert(i, thousandSeparator);
+ }
+ else {
break;
}
}
- String numberText = numberParts.join('');
-
- return numberText;
+ return textRepresentation.reversed.join('');
}
}
diff --git a/publish.sh b/publish.sh
deleted file mode 100644
index ee1573c..0000000
--- a/publish.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env bash
-flutter test && flutter packages pub publish
\ No newline at end of file
diff --git a/pubspec.lock b/pubspec.lock
index 1adaf5c..224c7bb 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -1,69 +1,34 @@
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
packages:
- analyzer:
- dependency: transitive
- description:
- name: analyzer
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.31.2-alpha.2"
- args:
- dependency: transitive
- description:
- name: args
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.4.3"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
- version: "2.0.7"
+ version: "2.0.8"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
- version: "1.0.3"
+ version: "1.0.4"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.1"
+ version: "1.1.2"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
- version: "1.14.6"
- convert:
- dependency: transitive
- description:
- name: convert
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.0.1"
- crypto:
- dependency: transitive
- description:
- name: crypto
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.0.3"
- csslib:
- dependency: transitive
- description:
- name: csslib
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.14.4"
+ version: "1.14.11"
flutter:
dependency: "direct main"
description: flutter
@@ -74,290 +39,94 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
- front_end:
- dependency: transitive
- description:
- name: front_end
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.1.0-alpha.12"
- glob:
- dependency: transitive
- description:
- name: glob
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.1.5"
- html:
- dependency: transitive
- description:
- name: html
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.13.3"
- http:
- dependency: transitive
- description:
- name: http
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.11.3+16"
- http_multi_server:
- dependency: transitive
- description:
- name: http_multi_server
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.0.4"
- http_parser:
- dependency: transitive
- description:
- name: http_parser
- url: "https://pub.dartlang.org"
- source: hosted
- version: "3.1.2"
- io:
- dependency: transitive
- description:
- name: io
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.3.2+1"
- js:
- dependency: transitive
- description:
- name: js
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.6.1"
- kernel:
- dependency: transitive
- description:
- name: kernel
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.3.0-alpha.12"
- logging:
- dependency: transitive
- description:
- name: logging
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.11.3+1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
- version: "0.12.2+1"
+ version: "0.12.3+1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.5"
- mime:
- dependency: transitive
- description:
- name: mime
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.9.6"
- multi_server_socket:
- dependency: transitive
- description:
- name: multi_server_socket
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.0.1"
- node_preamble:
- dependency: transitive
- description:
- name: node_preamble
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.4.1"
- package_config:
- dependency: transitive
- description:
- name: package_config
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.0.3"
- package_resolver:
- dependency: transitive
- description:
- name: package_resolver
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.0.2"
+ version: "1.1.6"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
- version: "1.5.1"
- plugin:
- dependency: transitive
- description:
- name: plugin
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.2.0+2"
- pool:
- dependency: transitive
- description:
- name: pool
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.4"
- pub_semver:
- dependency: transitive
- description:
- name: pub_semver
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.4.1"
+ version: "1.6.2"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
- version: "0.29.0+1"
- shelf:
- dependency: transitive
- description:
- name: shelf
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.7.3"
- shelf_packages_handler:
- dependency: transitive
- description:
- name: shelf_packages_handler
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.0.3"
- shelf_static:
- dependency: transitive
- description:
- name: shelf_static
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.2.7"
- shelf_web_socket:
- dependency: transitive
- description:
- name: shelf_web_socket
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.2.2"
+ version: "2.0.1"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
- source_map_stack_trace:
- dependency: transitive
- description:
- name: source_map_stack_trace
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.1.4"
- source_maps:
- dependency: transitive
- description:
- name: source_maps
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.10.5"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
- version: "1.4.0"
+ version: "1.4.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
- version: "1.9.2"
+ version: "1.9.3"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
- version: "1.6.6"
+ version: "1.6.8"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
- version: "1.0.2"
+ version: "1.0.4"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
- version: "1.0.0"
- test:
+ version: "1.0.1"
+ test_api:
dependency: transitive
description:
- name: test
+ name: test_api
url: "https://pub.dartlang.org"
source: hosted
- version: "0.12.37"
+ version: "0.2.1"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.5"
- utf:
- dependency: transitive
- description:
- name: utf
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.9.0+4"
+ version: "1.1.6"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
- version: "2.0.6"
- watcher:
- dependency: transitive
- description:
- name: watcher
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.9.7+7"
- web_socket_channel:
- dependency: transitive
- description:
- name: web_socket_channel
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.0.7"
- yaml:
- dependency: transitive
- description:
- name: yaml
- url: "https://pub.dartlang.org"
- source: hosted
- version: "2.1.13"
+ version: "2.0.8"
sdks:
- dart: ">=2.0.0-dev.52.0 <=2.0.0-dev.54.0.flutter-46ab040e58"
+ dart: ">=2.0.0 <3.0.0"
diff --git a/pubspec.yaml b/pubspec.yaml
index 6deb40b..a07cb76 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,53 +1,51 @@
name: flutter_masked_text
description: Masked text input for flutter.
-version: 0.5.0
+version: 0.8.0
author: Ben-hur Santos Ott
homepage: https://github.com/benhurott/flutter-masked-text
dependencies:
- flutter:
- sdk: flutter
+ flutter:
+ sdk: flutter
dev_dependencies:
- flutter_test:
- sdk: flutter
+ flutter_test:
+ sdk: flutter
environment:
- sdk: '>=1.23.0 <=2.0.0'
+ sdk: '>=1.23.0 <3.0.0'
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
-
- # To add assets to your package, add an assets section, like this:
- # assets:
- # - images/a_dot_burr.jpeg
- # - images/a_dot_ham.jpeg
- #
- # For details regarding assets in packages, see
- # https://flutter.io/assets-and-images/#from-packages
- #
- # An image asset can refer to one or more resolution-specific "variants", see
- # https://flutter.io/assets-and-images/#resolution-aware.
-
- # To add custom fonts to your package, add a fonts section here,
- # in this "flutter" section. Each entry in this list should have a
- # "family" key with the font family name, and a "fonts" key with a
- # list giving the asset and other descriptors for the font. For
- # example:
- # fonts:
- # - family: Schyler
- # fonts:
- # - asset: fonts/Schyler-Regular.ttf
- # - asset: fonts/Schyler-Italic.ttf
- # style: italic
- # - family: Trajan Pro
- # fonts:
- # - asset: fonts/TrajanPro.ttf
- # - asset: fonts/TrajanPro_Bold.ttf
- # weight: 700
- #
- # For details regarding fonts in packages, see
- # https://flutter.io/custom-fonts/#from-packages
+ # To add assets to your package, add an assets section, like this:
+ # assets:
+ # - images/a_dot_burr.jpeg
+ # - images/a_dot_ham.jpeg
+ #
+ # For details regarding assets in packages, see
+ # https://flutter.io/assets-and-images/#from-packages
+ #
+ # An image asset can refer to one or more resolution-specific "variants", see
+ # https://flutter.io/assets-and-images/#resolution-aware.
+ # To add custom fonts to your package, add a fonts section here,
+ # in this "flutter" section. Each entry in this list should have a
+ # "family" key with the font family name, and a "fonts" key with a
+ # list giving the asset and other descriptors for the font. For
+ # example:
+ # fonts:
+ # - family: Schyler
+ # fonts:
+ # - asset: fonts/Schyler-Regular.ttf
+ # - asset: fonts/Schyler-Italic.ttf
+ # style: italic
+ # - family: Trajan Pro
+ # fonts:
+ # - asset: fonts/TrajanPro.ttf
+ # - asset: fonts/TrajanPro_Bold.ttf
+ # weight: 700
+ #
+ # For details regarding fonts in packages, see
+ # https://flutter.io/custom-fonts/#from-packages
diff --git a/test/flutter_masked_text_test.dart b/test/flutter_masked_text_test.dart
index 699629a..e1c90d8 100644
--- a/test/flutter_masked_text_test.dart
+++ b/test/flutter_masked_text_test.dart
@@ -1,15 +1,28 @@
-import 'package:test/test.dart';
+import 'package:flutter_test/flutter_test.dart';
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');
@@ -119,7 +132,9 @@ void main() {
expect(executor, throwsArgumentError);
});
- test('rightSymbol " US\$" with 12345678901234 must results in 123.456.789.012,34 US\$', () {
+ test(
+ 'rightSymbol " US\$" with 12345678901234 must results in 123.456.789.012,34 US\$',
+ () {
var controller = new MoneyMaskedTextController(rightSymbol: ' US\$');
controller.updateValue(123456789012.34);
@@ -132,5 +147,12 @@ void main() {
expect(controller.text, 'R\$ 123,45');
});
+
+ test('precision 3 and value 123.45 results in "123,450"', () {
+ var controller = new MoneyMaskedTextController(precision: 3);
+ controller.updateValue(123.45);
+
+ expect(controller.text, '123,450');
+ });
});
}