Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Number is reset to initial value on pressing the "Done" button #28

Open
roland-jungwirth opened this issue May 7, 2019 · 2 comments
Open

Comments

@roland-jungwirth
Copy link

Similarly to the closed issue, I am having a problem when clicking on the "Done" button. The displayed value is reset to the initial value (0.00 in most cases) when using the MoneyMaskedTextController. I can reproduce this on iPhone 5 and Android simulated and on a Samsung s10. I've stripped all my logic out of the code and still the issue happens. Should you need more information, please feel free to check in.

This is my implementation of the issue (I have stripped out unnecessary containers, etc. but I have tested it and it does the same):

Widget _createCurrencyField(Field field) {
    final _currencyController = MoneyMaskedTextController(
        initialValue: 0.0,
        decimalSeparator: ',',
        thousandSeparator: '.',
        rightSymbol: '',
        leftSymbol: '€');

     return TextField(
            controller: _currencyController,
            keyboardType: TextInputType.number,
          );
  }
@soonsam123
Copy link

soonsam123 commented Jul 15, 2019

Storing the Controller in a global variable worked for me.

class _LoginPageState extends State<LoginPage> {
  MaskedTextController controller = MaskedTextController(mask: '000.000.000-00');

@override
  Widget build(BuildContext context) {
  ...
  }

Widget _buildCampoCPF() {
    return Container(
      margin: EdgeInsets.only(top: 20.0),
      child: TextFormField(
        controller: controller,
        ...
      ),
    );
  }

Got the idea from issue #13

@rockerbacon
Copy link

rockerbacon commented Jul 18, 2019

Storing the controller in a variable did not work for me

EDIT: What did work was making the Widget stateful instead of stateless

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants