gtgalone / currency_text_input_formatter Goto Github PK
View Code? Open in Web Editor NEWCurrency Text Input Formatter for Flutter.
Home Page: https://pub.dev/packages/currency_text_input_formatter
License: MIT License
Currency Text Input Formatter for Flutter.
Home Page: https://pub.dev/packages/currency_text_input_formatter
License: MIT License
feature request please?
an option to do left to right or (right to left, your default)
FormBuilderTextField(
name: 'value',
decoration: const InputDecoration(
labelText: 'Valor'
),
inputFormatters: [
CurrencyTextInputFormatter(
locale: 'pt-br',
decimalDigits: 2,
symbol: '',
),
],
keyboardType: TextInputType.number,
onChanged: (value) => log(value!.replaceAll('.', '').replaceAll(',', '.')),
initialValue: action == 'edit' ? _formatter.format(vm.movement.value.toString()) : '',
),
I set symbol as an empty string, and it renders like this:
But when initialValue is set, the symbol appears anyway:
Can someone help me? 😁🙏
thanks!
I'm trying to increment the value of CurrencyTextInputFormatter using a button but I haven't come up with a way to make it increment and display the formatting, would I have some direction to offer
Thanks for your supporting.
When used with textfield ,the output I get is something like this:
USD20,000
.
Is there a way to get a formatted currency without the currency, like this:
20,000
.
?
hi!
i have a problem, when after delete all number in a text form field, then remains "0"
then i enter number 1, it become "01". (1 behind 0)
how to directly replace 0 to 1?
thanks
The cursor selection is always behind the currency abbreviation, however the user might expect it to be right before it as the text changes there.
If the user wants to remove a digit in the middle to replace it to something else (ex. 1,000.00 to 1,500.00), the cursor moves to the end which is for me not a good user experience. I end up retyping the whole amount. Is there an existing way to prevent this behavior?
Current behaviour
A Field with a controller and an initial value, upon selecting the field text is highlighted as expected but then attempting to type in new values results in no changes.
Expected behaviour
Selecting a field that has default text, highlights the current text, upon typing clears the field and starts as text input with formatting as usual as if there was no initial value.
Sample code.
TextEditingController _testController;
final FocusNode _testFocus = FocusNode();
final CurrencyTextInputFormatter _formatter = CurrencyTextInputFormatter(symbol: '$');
// init
_testController = TextEditingController(text: _formatter.format('123'));
_testFocus.addListener(() {
_testController.selection = TextSelection(
baseOffset: 0,
extentOffset: _testController.text.length,
);
});
// build
TextFormField(
focusNode: _testFocus,
controller: _testController,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[_formatter],
),
Please implement support for minimum and maximum value
in this code i try to enable or disable formatter on textformField, but i can't
formatter = false;
formatter?
CurrencyTextInputFormatter(
locale: 'en',
decimalDigits: 0,
symbol: ',',
)
:null /* nothing*/,
I have added the formatter to textformfield, but when i try to parse the controller.text, it fails.
reason: I cannot remove empty space inside numbers.
What is the problem? How can i remove empty spaces and parse it to number?
Code :
TextFormField(
initialValue: '12340',
keyboardType: TextInputType.number,
inputFormatters: [
CurrencyTextInputFormatter(decimalDigits: 0, symbol: ''),
],
)
Flutter Doctor :
[✓] Flutter (Channel stable, 2.10.2, on macOS 12.3.1 21E258 darwin-arm, locale en-ID)
• Flutter version 2.10.2 at /Users/Tara/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 097d3313d8 (4 months ago), 2022-02-18 19:33:08 -0600
• Engine revision a83ed0e5e3
• Dart version 2.16.1
• DevTools version 2.9.2
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
• Android SDK at /Users/Tara/Library/Android/sdk
• Platform android-32, build-tools 32.1.0-rc1
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
Its not working flutter 3.0 version pls update
I'm experiencing an issue where this happens:
keyboardType: TextInputType.number
or TextInputType.numberWithOptions
(for the default keyboardType, it works normally)It seems this is due to Flutter's framework calling formatEditUpdate
twice after a backspace press. Googling a bit, I found this issue which might be related (it was solved, but later rolled back) - the issue also seemed to happen only with the number keyboard: flutter/flutter#48608
I added a log statement to formatEditUpdate
and noticed that it indeed was being called more than once. Now, this method being called more than once wouldn't be a problem if it weren't for lines 49-52:
49 String oldText = oldValue.text.replaceAll(RegExp('[^0-9]'), '');
50 if (newText == oldText) {
51 newText = newText.substring(0, newText.length - 1);
52 }
From what I've seen, the framework calls (for a single backspace press):
formatEditUpdate(oldValue: "123.45", newValue: "123.4") -> returns "12.34"
formatEditUpdate(oldValue: "12.34", newValue: "123.4") -> returns "1.23"
In the second call, the if condition is true, and the return value is stripped out of the last digit.
Removing lines 49-52 seem to make it work fine for me (the method still gets called twice, but only a single digit gets erased). However, I imagine there's a reason for those lines to be there in the first place, so before sending a PR, I wanted to ask: what is the logic behind that if condition? Does removing it break some other case?
It is useful to have a static method for use in pre-filled forms and data tables. Can you please add a static method to format strings for initial values?
I am passing formatter to inputFormatters like this:
CurrencyTextInputFormatter(
decimalDigits: 2,
symbol: '',
locale: 'ru',
),
Trying to input integer number like "123", but getting "1,23" - This behavior is very uncomfortable for users.
This will be great to have a prop to control it and allow users to enter decimals manually with dot or comma.
This is like autonumeric
works: http://autonumeric.org/
Hi,
i think the way how you work with decimal points in your library is a bit confusing and I try to explain this by a small sample:
How it is:
Entered value for 100 + click on decimal separator + 99 results in: 10,000.99
How it should be:
Entered value for 100 + click on decimal separator + 99 results in: 100.99
Your formatter seems always to add new values to the decimal points and shift the main number to the left instead. This behaviour is compared to normal calculators very atypical and hard to maintain is you want to correct a number input.
Tested on 2.1.5
if i use decimalDigits: 2 it input in decimal first its a bug. cause 2 decimal should be visible when i press . keyword.
Hi,
Could you please update to intl 0.18.0 dependecy?
thanks
By creating the following formatter (I'm using locale = 'es', but this applies to other locales too):
var formatter = CurrencyTextInputFormatter(locale: 'es', symbol: '');
The formatter adds an extra space when formatting. That is, after typing "0", the above formatter returns "0,00 ". For some locales, such as pt_BR, the extra space can be in the front (i.e., " 0,00").
This is because NumberFormat.currency doesn't handle the symbol being empty, instead it expects either a null symbol (in which case it formats with the locale ISO code) or some non-empty string, in which case it would format as "0,00 €", in locale es, or "R$ 0,00", in locale pt_BR.
However, since Flutter's TextField includes preffixText
and suffixText
as decoration properties, I assume it's a fairly common case to use, for example, preffixText = r'R$'
, and then show no symbol in the actual text field string. In that case, this extra space is counter-intuitive (and was bugging my parser haha).
I believe this fix is very simple, just requires adding a trim()
on the string after formatting. I'm submitting a PR for it, along with some unit tests to validate the changes. Feel free to point any issues :)
I haven't found a way to add a trailing symbol I'm missing something or there's really no way to add a trailing symbol
hi. how can it be formatted by default? this is my code
TextFormField(
decoration: InputDecoration(labelText: tr('premium')),
enabled: connectivityResult != ConnectivityResult.none,
initialValue: _policy?.premium == 0 ? '' : _policy?.premium.toString(),
inputFormatters: [ CurrencyTextInputFormatter(symbol: '') ],
keyboardType: TextInputType.numberWithOptions(decimal: true),
textInputAction: TextInputAction.next,
validator: (String? value) {
return value!.isEmpty ? tr('premium_blank') : null;
},
onChanged: (value) {
if (value.replaceAll(',', '').length > 0)
_policy?.premium = double.parse(value.replaceAll(',', ''));
},
),
The lib works ok when typing. but when it's loaded, it doesnt do any formatting.
Hi. Is it possible to make it so that the integer part is entered first and then the decimal part?
getUnformattedValue does not return negative amount when negative amount was entered.
Hi, Whenever I go to the next step after I inputted the value on the TextFormField
the formatter.getUnformattedValue().toInt()
returns the expected value however when I go to the next step the formatter
value resets back to the intialValue
it doesn't keep the input value. How do I keep the value on Stepper
?
Example snippet
https://pastebin.com/ULWBxnpD
Hi @gtgalone
Is there a simple way to obtain the value of textfield without the mask? If a regular expression is necessary, you could provide it in the documentation, thanks.
Edit:
Reading the code from the lib with this regular expression replaceAll (RegExp ('[^ 0-9]'), '') I can get the numeric value but without taking into account the decimals, it would be great if the textInputFormatter had a getter that give the double value with decimals that the textField has
I know this is a ridiculous big number but is still worth fixing.
currency_text_input_formatter: ^2.1.7```
El paquete no funciona cuando asigno el parametro locale como CLP (peso chileno)
Hi, can you add an option to disable negatives?
Any chance we're getting an upgrade ?
I would be great if the decimal points are optional and the format not shown if the user does not tap the period (.) to enter the decimal points.
1,250
if user enters .99
then show decimal format
1,250.99
Thank you
See #13
Hi, I think your package is very helpful and I would love to use it. Unfortunately the Delete-Key on the number keyboard doesn't do anything right now. The user can't correct his/her input this way.
Hi, I like your package and would love to use it. Unfortunately it doesn't properly work at the moment, when the currency symbol is positioned at the end. For example in Germany the currency is formatted as '25.000,00 €', which is correct. But then the delete key doesn't work anymore.
Hello, I saw your last release today, thank you for your great job.
Just one point, could you update intl to ^0.19.0 in dependencies settings
Best regards,
hello, I have
TextFormField(
inputFormatters: [CurrencyTextInputFormatter(locale: "en_US", decimalDigits: 2, symbol: "")],
keyboardType: TextInputType.numberWithOptions(decimal: true)
);
and when I type 1
it goes to 0.01
is there a way to start from 1
and only if I press ,
to add a decimal? It feels very unnatural to start from 0.01 cent
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.