GithubHelp home page GithubHelp logo

gtgalone / currency_text_input_formatter Goto Github PK

View Code? Open in Web Editor NEW
49.0 49.0 27.0 136 KB

Currency Text Input Formatter for Flutter.

Home Page: https://pub.dev/packages/currency_text_input_formatter

License: MIT License

Dart 100.00%

currency_text_input_formatter's People

Contributors

alfinsyahruddin avatar gtgalone avatar holtalanm avatar laripeanuts avatar luistrivelatto avatar manerilu avatar mclean25 avatar yuriescl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

currency_text_input_formatter's Issues

Input left to right

feature request please?
an option to do left to right or (right to left, your default)

Symbol appears when initialValue is set

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:

image

But when initialValue is set, the symbol appears anyway:

image

Can someone help me? 😁🙏

thanks!

Trying to increment using button

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

Manual input dot (.) for decimal number

Hi,
Thanks for your library.
I have an issue.
I want to manual input the dot (.) for decimal number
But if i set decimalDigits: 0, i cannot input the dot (.)
If i set decimalDigits: 2, it is auto input dot (.) when i input the first number
ex: 1 -> 0.01
--- my setting currency for the indian currency ---
CurrencyTextInputFormatter(
symbol: '',
decimalDigits: 0,
locale: 'en_IN',
)

Thanks for your supporting.

Screen.Recording.2023-05-08.at.15.20.24.mov

Prevent cursor from moving to the end of string

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?

Text selection bug

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],
),

Cannot parse text to num in TextEditingController

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?

Cannot delete or input number before adding number on first index of text selection

currency_text_input_formatter

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)

Pressing backspace erases two digits at once

I'm experiencing an issue where this happens:

  1. Create TextField with keyboardType: TextInputType.number or TextInputType.numberWithOptions (for the default keyboardType, it works normally)
  2. TextField = "123.45"
  3. Press backspace on the Android keyboard
  4. TextField = "1.23" (expected: "12.34")

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?

Value alignment

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/

Working with decimal points is atypical

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

Formatter returns an extra space when formatting with some locales and with symbol = ''

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 :)

Add Trailing Symbol

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

Format default value in TextFormField

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.

Reverse input behavior

Hi. Is it possible to make it so that the integer part is entered first and then the decimal part?

negative amount

getUnformattedValue does not return negative amount when negative amount was entered.

How to get the current value of the textfield without mask

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

locale CLP

El paquete no funciona cuando asigno el parametro locale como CLP (peso chileno)

Make the decimal points optional

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

The Delete-Button doesn't work

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.

Delete-Button doesn't work when currency symbol is at the end

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.

Dependency upgrade

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,

Issue on format with CurrencyTextInputFormatter

Hi,

I just want to share an issue than annoy me with CurrencyTextInputFormatter is that if I want to format that value : 20.0 , It will format as 2.00 for example.

In my case I want to init an input with 131.0 (double value) as value and that is my output using formatter :
image

Did you know that issue ?

Start value

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.