flutter-masked-text icon indicating copy to clipboard operation
flutter-masked-text copied to clipboard

Problem with MoneyMaskedTextController cursor

Open erpriliano opened this issue 5 years ago • 12 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

erpriliano avatar Mar 04 '20 04:03 erpriliano

same here, anyone resolve ?

rafaelmpessoa avatar Apr 02 '20 14:04 rafaelmpessoa

Try this

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

phungnc avatar Apr 06 '20 05:04 phungnc

Same problem here using the MaskedTextController...

alanbre avatar Apr 14 '20 18:04 alanbre

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

azamatdev avatar Apr 21 '20 23:04 azamatdev

@benhurott we need your help, sir

erpriliano avatar Apr 24 '20 05:04 erpriliano

@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,
...

phungnc avatar May 08 '20 04:05 phungnc

@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.

hikmawanaz avatar Aug 26 '20 04:08 hikmawanaz

Any solution for this issue?

hikmawanaz avatar Aug 26 '20 04:08 hikmawanaz

@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();
  }
};

rumarka avatar Dec 24 '20 10:12 rumarka

Anu update? I have the same issue

leszekkrol avatar Jan 02 '21 18:01 leszekkrol

2021 year but this bug still work. any updates?

romreed avatar Feb 17 '21 16:02 romreed

use another library is only the one solution

hikmawanaz avatar Feb 20 '21 23:02 hikmawanaz