Skip to content

Commit 3bc8fa8

Browse files
committed
ncm e cest formatters
1 parent 57c81dd commit 3bc8fa8

File tree

11 files changed

+128
-8
lines changed

11 files changed

+128
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.12.0
2+
- Novos formatters: `CESTInputFormatter()` e `NCMInputFormatter()`, por [juliogyn](https://github.com/juliogyn).
3+
14
## 1.11.0
25
- Novo formatter: `IOFInputFormatter()`.
36

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,11 @@ Para inicializar um `TextEditingController` com o texto já formatado, basta esc
132132
final dataController = TextEditingController(text: UtilData.obterDataDDMMAAAA(DateTime(2020, 12, 31)));
133133
final cnpjController = TextEditingController(text: UtilBrasilFields.obterCnpj('11222333444455'));
134134
```
135+
136+
---
137+
138+
<a href="https://github.com/flutterbootcamp/brasil_fields/graphs/contributors">
139+
<img src="https://contrib.rocks/image?repo=flutterbootcamp/brasil_fields" />
140+
</a>
141+
142+
Made with [contrib.rocks](https://contrib.rocks).

example/lib/main.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ class MyApp extends StatelessWidget {
114114
label: 'IOF',
115115
formatter: IOFInputFormatter(),
116116
),
117+
RowFormatters(
118+
label: 'NCM',
119+
formatter: NCMInputFormatter(),
120+
),
121+
RowFormatters(
122+
label: 'CEST',
123+
formatter: CESTInputFormatter(),
124+
),
117125
],
118126
),
119127
const Text('Em breve'),

example/macos/Runner.xcodeproj/project.pbxproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 51;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXAggregateTarget section */
@@ -235,6 +235,7 @@
235235
/* Begin PBXShellScriptBuildPhase section */
236236
3399D490228B24CF009A79C7 /* ShellScript */ = {
237237
isa = PBXShellScriptBuildPhase;
238+
alwaysOutOfDate = 1;
238239
buildActionMask = 2147483647;
239240
files = (
240241
);
@@ -344,7 +345,7 @@
344345
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
345346
GCC_WARN_UNUSED_FUNCTION = YES;
346347
GCC_WARN_UNUSED_VARIABLE = YES;
347-
MACOSX_DEPLOYMENT_TARGET = 10.11;
348+
MACOSX_DEPLOYMENT_TARGET = 10.14;
348349
MTL_ENABLE_DEBUG_INFO = NO;
349350
SDKROOT = macosx;
350351
SWIFT_COMPILATION_MODE = wholemodule;
@@ -423,7 +424,7 @@
423424
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
424425
GCC_WARN_UNUSED_FUNCTION = YES;
425426
GCC_WARN_UNUSED_VARIABLE = YES;
426-
MACOSX_DEPLOYMENT_TARGET = 10.11;
427+
MACOSX_DEPLOYMENT_TARGET = 10.14;
427428
MTL_ENABLE_DEBUG_INFO = YES;
428429
ONLY_ACTIVE_ARCH = YES;
429430
SDKROOT = macosx;
@@ -470,7 +471,7 @@
470471
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
471472
GCC_WARN_UNUSED_FUNCTION = YES;
472473
GCC_WARN_UNUSED_VARIABLE = YES;
473-
MACOSX_DEPLOYMENT_TARGET = 10.11;
474+
MACOSX_DEPLOYMENT_TARGET = 10.14;
474475
MTL_ENABLE_DEBUG_INFO = NO;
475476
SDKROOT = macosx;
476477
SWIFT_COMPILATION_MODE = wholemodule;

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ packages:
2323
path: ".."
2424
relative: true
2525
source: path
26-
version: "1.11.0"
26+
version: "1.12.0"
2727
characters:
2828
dependency: transitive
2929
description:

lib/brasil_fields.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ export 'src/formatters/altura_input_formatter.dart';
44
export 'src/formatters/cartao_bancario_input_formatter.dart';
55
export 'src/formatters/centavos_input_formatter.dart';
66
export 'src/formatters/cep_input_formatter.dart';
7+
export 'src/formatters/cest_input_formatter.dart';
78
export 'src/formatters/cnpj_input_formatter.dart';
89
export 'src/formatters/compound_formatters/cpf_ou_cpnj_formatter.dart';
910
export 'src/formatters/cpf_input_formatter.dart';
1011
export 'src/formatters/data_input_formatter.dart';
1112
export 'src/formatters/hora_input_formatter.dart';
1213
export 'src/formatters/iof_input_formatter.dart';
1314
export 'src/formatters/km_input_formatter.dart';
15+
export 'src/formatters/ncm_input_formatter.dart';
1416
export 'src/formatters/peso_input_formatter.dart';
1517
export 'src/formatters/placa_veiculo_formatter.dart';
1618
export 'src/formatters/real_input_formatter.dart';
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import 'package:brasil_fields/src/interfaces/compoundable_formatter.dart';
2+
import 'package:flutter/services.dart';
3+
4+
/// Formata o valor do campo com a máscara CEST `XX.XXX.XX`.
5+
class CESTInputFormatter extends TextInputFormatter
6+
implements CompoundableFormatter {
7+
// Define o tamanho máximo do campo.
8+
@override
9+
int get maxLength => 7;
10+
11+
@override
12+
TextEditingValue formatEditUpdate(
13+
TextEditingValue oldValue, TextEditingValue newValue) {
14+
final newValueLength = newValue.text.length;
15+
16+
if (newValueLength > maxLength) {
17+
return oldValue;
18+
}
19+
20+
var selectionIndex = newValue.selection.end;
21+
var substrIndex = 0;
22+
final newText = StringBuffer();
23+
24+
if (newValueLength >= 3) {
25+
newText.write('${newValue.text.substring(0, substrIndex = 2)}.');
26+
if (newValue.selection.end >= 2) selectionIndex++;
27+
}
28+
if (newValueLength >= 6) {
29+
newText.write('${newValue.text.substring(2, substrIndex = 5)}.');
30+
if (newValue.selection.end >= 5) selectionIndex++;
31+
}
32+
33+
if (newValueLength >= substrIndex) {
34+
newText.write(newValue.text.substring(substrIndex));
35+
}
36+
37+
return TextEditingValue(
38+
text: newText.toString(),
39+
selection: TextSelection.collapsed(offset: selectionIndex),
40+
);
41+
}
42+
}

lib/src/formatters/iof_input_formatter.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'package:flutter/services.dart';
22

3-
/// Formata o valor do campo com a máscara `9,99999`.
4-
3+
/// Formata o valor do campo com a máscara `9,99999`
54
class IOFInputFormatter extends TextInputFormatter {
65
@override
76
TextEditingValue formatEditUpdate(
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'package:brasil_fields/src/interfaces/compoundable_formatter.dart';
2+
import 'package:flutter/services.dart';
3+
4+
/// Formata o valor do campo com a máscara de NCM: `XXXX.XX.XX`
5+
class NCMInputFormatter extends TextInputFormatter
6+
implements CompoundableFormatter {
7+
@override
8+
int get maxLength => 8;
9+
10+
@override
11+
TextEditingValue formatEditUpdate(
12+
TextEditingValue oldValue, TextEditingValue newValue) {
13+
final newValueLength = newValue.text.length;
14+
15+
if (newValueLength > maxLength) {
16+
return oldValue;
17+
}
18+
19+
var selectionIndex = newValue.selection.end;
20+
var substrIndex = 0;
21+
final newText = StringBuffer();
22+
23+
if (newValueLength >= 5) {
24+
newText.write('${newValue.text.substring(0, substrIndex = 4)}.');
25+
if (newValue.selection.end >= 4) selectionIndex++;
26+
}
27+
if (newValueLength >= 7) {
28+
newText.write('${newValue.text.substring(4, substrIndex = 6)}.');
29+
if (newValue.selection.end >= 6) selectionIndex++;
30+
}
31+
32+
if (newValueLength >= substrIndex) {
33+
newText.write(newValue.text.substring(substrIndex));
34+
}
35+
36+
return TextEditingValue(
37+
text: newText.toString(),
38+
selection: TextSelection.collapsed(offset: selectionIndex),
39+
);
40+
}
41+
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: brasil_fields
22
description: O jeito mais fácil de utilizar padrões e formatos brasileiros em seu projeto Dart.
3-
version: 1.11.0
3+
version: 1.12.0
44
homepage: https://github.com/flutterbootcamp/brasil_fields
55
repository: https://github.com/flutterbootcamp/brasil_fields
66
issue_tracker: https://github.com/flutterbootcamp/brasil_fields/issues

0 commit comments

Comments
 (0)