bhrott / flutter-masked-text

A masked text for Flutter.

Home Page:https://pub.dartlang.org/packages/flutter_masked_text

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with MoneyMaskedTextController cursor

erpriliano opened this issue · comments

Hi, I've got a problem below :

ezgif com-resize (1)

The cursor always seem to move to the start of the textfield. Is there any solution to this? Cause this happens to give user a bad experience when filling in the form.

My code that related to this :

final _priceController = MoneyMaskedTextController(
    precision: 0, 
    decimalSeparator: '', 
    thousandSeparator: ',',
  );

Awaiting your response, sir

same here, anyone resolve ?

Try this

 controller.afterChange = (_, __) {
      controller.selection = TextSelection.collapsed(
        offset: controller.text.length,
      );
    };

Same problem here using the MaskedTextController...

The same problem. @phungnc could you clarify how to use your code. I tried to add it but could not make it

@benhurott we need your help, sir

@azamatdev

  1. create a MoneyMaskedTextController:
final myController = new MoneyMaskedTextController();
  1. inside your initState, set the afterChange hook like this
  @override
  void initState() {
    super.initState();
    myController.afterChange = (_, __) {
      myController.selection = TextSelection.collapsed(
        offset: myController.text.length,
      );
    };
  }
  1. listening for changes to the text form field
 TextFormField(
     controller: myController,
...
commented

@azamatdev

  1. create a MoneyMaskedTextController:
final myController = new MoneyMaskedTextController();
  1. inside your initState, set the afterChange hook like this
  @override
  void initState() {
    super.initState();
    myController.afterChange = (_, __) {
      myController.selection = TextSelection.collapsed(
        offset: myController.text.length,
      );
    };
  }
  1. listening for changes to the text form field
 TextFormField(
     controller: myController,
...

I have tried this solution, it's work but not perfectly. In iOS devices, this solution make backspace(delete) not working.

commented

Any solution for this issue?

@azamatdev

  1. create a MoneyMaskedTextController:
final myController = new MoneyMaskedTextController();
  1. inside your initState, set the afterChange hook like this
  @override
  void initState() {
    super.initState();
    myController.afterChange = (_, __) {
      myController.selection = TextSelection.collapsed(
        offset: myController.text.length,
      );
    };
  }
  1. listening for changes to the text form field
 TextFormField(
     controller: myController,
...

I have tried this solution, it's work but not perfectly. In iOS devices, this solution make backspace(delete) not working.

myController.afterChange = (previous, next) {
  if (previous.length < next.length) {
    myController.moveCursorToEnd();
  }
};

Anu update? I have the same issue

2021 year but this bug still work. any updates?

commented

use another library is only the one solution