Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter textfield Flutter RTL cursor position problem n-1

I don't know if the problem is old but I tried all ways to find a solution without success. the problem when select letter n in input field the cursor jump to n-1 the problem shown in video included , problem in rtl only

The link contains the code and a video of the problem.

the code : link here

the video : link here

like image 256
Ebrahim Halabi Avatar asked Jun 29 '26 21:06

Ebrahim Halabi


1 Answers

I think this because of some characters is encoded as 2 to 4 bytes.

Anyway this snippet can do the trick

TextField(
     onTap: (){
          if(controller.selection == TextSelection.fromPosition(TextPosition(offset: controller.text.length -1))){
             setState(() {
                 controller.selection = TextSelection.fromPosition(TextPosition(offset: controller.text.length));
             });
           }
     },
     controller: controller,
     ...
);
like image 164
Omar Alkattan Avatar answered Jul 01 '26 13:07

Omar Alkattan