-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
483d4e8
commit 4c8fe3f
Showing
9 changed files
with
70 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
## 1.14.0 | ||
- Novo formatter: `CNSInputFormatter()` | ||
|
||
## 1.13.1 | ||
- intl: 0.18.0. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:flutter/services.dart'; | ||
|
||
/// Formata o valor do campo com a máscara `000 1111 2222 3333`. | ||
class CNSInputFormatter extends TextInputFormatter { | ||
@override | ||
TextEditingValue formatEditUpdate( | ||
TextEditingValue oldValue, TextEditingValue newValue) { | ||
final newValueLength = newValue.text.length; | ||
|
||
// Verifica o tamanho máximo do campo. | ||
if (newValueLength > 15) { | ||
return oldValue; | ||
} | ||
|
||
var selectionIndex = newValue.selection.end; | ||
var substrIndex = 0; | ||
final newText = StringBuffer(); | ||
|
||
if (newValueLength >= 3) { | ||
newText.write('${newValue.text.substring(0, substrIndex = 3)} '); | ||
if (newValue.selection.end >= 4) selectionIndex++; | ||
} | ||
if (newValueLength >= 7) { | ||
newText.write('${newValue.text.substring(3, substrIndex = 7)} '); | ||
if (newValue.selection.end >= 8) selectionIndex++; | ||
} | ||
if (newValueLength >= 11) { | ||
newText.write('${newValue.text.substring(7, substrIndex = 11)} '); | ||
if (newValue.selection.end >= 12) selectionIndex++; | ||
} | ||
if (newValueLength >= substrIndex) { | ||
newText.write(newValue.text.substring(substrIndex)); | ||
} | ||
|
||
return TextEditingValue( | ||
text: newText.toString(), | ||
selection: TextSelection.collapsed(offset: selectionIndex), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters