Reputation: 83
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
Upvotes: 8
Views: 1008
Reputation: 134
The answer that has been submitted as correct answer, does not work on cursor movement. It only works on tap.
You can fix this by registering a listener on text editing controller and watch over the cursor position:
@override
void initState() {
super.initState();
_textEditingController.addListener((){
if (_textEditingController != null) {
if (_textEditingController.selection ==
TextSelection.fromPosition(
TextPosition(
offset: _textEditingController.text.length -
1,
),
)) {
_textEditingController.selection =
TextSelection.fromPosition(
TextPosition(
offset: _textEditingController.text.length,
),
);
}
}
}
);
}
Upvotes: 1
Reputation: 518
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,
...
);
Upvotes: 4