File tree 6 files changed +41
-17
lines changed 6 files changed +41
-17
lines changed Original file line number Diff line number Diff line change 2
2
3
3
- Initial library
4
4
- Support NumberTextInputFormatter, CurrencyTextInputFormatter and PercentageTextInputFormatter.
5
+
6
+ ## 1.0.0+1
7
+
8
+ - Check isNotEmpty before insert prefix or suffix.
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ Number Text Input Formatter for Flutter.
7
7
``` yaml
8
8
# Add into pubspec.yaml
9
9
dependencies :
10
- number_text_input_formatter : ^1.0.0
10
+ number_text_input_formatter : ^1.0.0+1
11
11
` ` `
12
12
13
13
## Usage
Original file line number Diff line number Diff line change @@ -15,6 +15,10 @@ abstract class TextValueEditor {
15
15
16
16
String get text;
17
17
18
+ bool get isEmpty;
19
+
20
+ bool get isNotEmpty;
21
+
18
22
TextEditingValue get inputValue;
19
23
20
24
MutableTextRange ? get selection;
@@ -55,6 +59,12 @@ class DefaultTextValueEditor implements TextValueEditor {
55
59
@override
56
60
int get length => codeUnits.length;
57
61
62
+ @override
63
+ bool get isEmpty => codeUnits.isEmpty;
64
+
65
+ @override
66
+ bool get isNotEmpty => codeUnits.isNotEmpty;
67
+
58
68
DefaultTextValueEditor (this .inputValue)
59
69
: selection = MutableTextRange .fromTextSelection (inputValue.selection),
60
70
composingRegion = MutableTextRange .fromComposingRange (inputValue.composing),
@@ -195,11 +205,17 @@ class LookupTextValueEditor implements TextValueEditor {
195
205
return editor[index];
196
206
}
197
207
208
+ @override
209
+ String get text => editor.text;
210
+
198
211
@override
199
212
int get length => editor.length;
200
213
201
214
@override
202
- String get text => editor.text;
215
+ bool get isEmpty => editor.isEmpty;
216
+
217
+ @override
218
+ bool get isNotEmpty => editor.isNotEmpty;
203
219
204
220
int get currentCode => editor[index];
205
221
Original file line number Diff line number Diff line change @@ -249,17 +249,19 @@ class TextNumberFilter {
249
249
}
250
250
251
251
void afterFilter () {
252
- if (decimalPoint != null ) {
253
- if (decimalDigits == 0 ) {
254
- insertDecimalDigits ();
255
- }
256
- } else {
257
- if (hasDecimalPoint) {
258
- insertDecimalPoint ();
252
+ if (editor.isNotEmpty) {
253
+ if (decimalPoint != null ) {
254
+ if (decimalDigits == 0 ) {
255
+ insertDecimalDigits ();
256
+ }
257
+ } else {
258
+ if (hasDecimalPoint) {
259
+ insertDecimalPoint ();
260
+ }
259
261
}
260
- }
261
262
262
- groupDigits ();
263
+ groupDigits ();
264
+ }
263
265
}
264
266
265
267
void insertDecimalDigits () {
Original file line number Diff line number Diff line change @@ -117,11 +117,13 @@ class NumberTextInputFormatter extends TextInputFormatter {
117
117
..prepare ({'removing' : oldValue.text.length - 1 == newValue.text.length})
118
118
..filter ();
119
119
120
- if (prefix != null ) {
121
- state.prefix (prefix! );
122
- }
123
- if (suffix != null ) {
124
- state.suffix (suffix! );
120
+ if (state.isNotEmpty) {
121
+ if (prefix != null ) {
122
+ state.prefix (prefix! );
123
+ }
124
+ if (suffix != null ) {
125
+ state.suffix (suffix! );
126
+ }
125
127
}
126
128
127
129
return state.finalize ();
Original file line number Diff line number Diff line change 1
1
name : number_text_input_formatter
2
2
description : Number Text Input Formatter for Flutter
3
- version : 1.0.0
3
+ version : 1.0.0+1
4
4
5
5
homepage : https://github.com/joutvhu/number_text_input_formatter
6
6
repository : https://github.com/joutvhu/number_text_input_formatter.git
You can’t perform that action at this time.
0 commit comments