Skip to content

Commit

Permalink
4.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Macacoazul01 committed Feb 21, 2024
1 parent 4058c6c commit 5158848
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [4.4.0] - 2024-02-19
- Added `doubleTextWithoutCurrencySymbol` getter to the controller. Now it is possible to return the number part of the controller as a String, formatted as a double (with `.` as decimal separator).
- Added a check to ensure that `thousandSymbol` and `decimalSymbol` ​​are not the same.

## [4.3.1] - 2024-02-19
- Added `maxValue` property to the controller. Now it is possible to define the maximum value the user is allowed to input. Everything greater than that will be forced to the maximum value.
- Fixed input of `initIntValue` when `numberOfDecimals` was different than 2.
Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: () {
print(_controller3.intValue);
print(_controller3.text);
print(_controller3.textWithoutCurrencySymbol);
print(_controller3.doubleTextWithoutCurrencySymbol);
},
child: const Text('Controller3 value'),
),
Expand Down
19 changes: 18 additions & 1 deletion lib/currency_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,31 @@ class CurrencyTextFieldController extends TextEditingController {
double _value = 0.0;
bool _isNegative = false;

///return the number part of the controller as a double.
double get doubleValue => _value.toPrecision(_numberOfDecimals);

///return the currency Symbol of the controller.
String get currencySymbol => _currencySymbol;

///return the decimal Symbol of the controller.
String get decimalSymbol => _decimalSymbol;

///return the thousand Symbol of the controller.
String get thousandSymbol => _thousandSymbol;

///return the number part of the controller as a int. Ex: `1000` for a controller with `R$ 10,00` text.
int get intValue =>
(_isNegative ? -1 : 1) *
(int.tryParse(_getOnlyNumbers(string: text) ?? '') ?? 0);

///return the number part of the controller as a String.
String get textWithoutCurrencySymbol =>
text.replaceFirst(_symbolSeparator, '');

///return the number part of the controller as a String, formatted as a double (with `.` as decimal separator).
String get doubleTextWithoutCurrencySymbol =>
text.replaceFirst(_symbolSeparator, '').replaceFirst(decimalSymbol, '.');

CurrencyTextFieldController({
String currencySymbol = 'R\$',
String decimalSymbol = ',',
Expand All @@ -87,7 +102,9 @@ class CurrencyTextFieldController extends TextEditingController {
bool currencyOnLeft = true,
bool enableNegative = true,
double? maxValue,
}) : _currencySymbol = currencySymbol,
}) : assert(thousandSymbol != decimalSymbol,
"thousandSymbol must be different from decimalSymbol."),
_currencySymbol = currencySymbol,
_decimalSymbol = decimalSymbol,
_thousandSymbol = thousandSymbol,
_currencySeparator = currencySeparator,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: currency_textfield
description: A flutter package that implements a Controller for currency text input.
version: 4.3.1
version: 4.4.0
homepage: https://github.com/IsaiasSantana/currency_textfield
environment:
sdk: '>=3.0.0 <4.0.0'
Expand Down

0 comments on commit 5158848

Please sign in to comment.