Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set cursor position at the end of the value in flutter in textfield?

Tags:

flutter

the problem is i want to add ",00" at the end of the value of the textfield works good in iOS device but in android cursor moves to starting point of the value in textfield. So, i'm unable to add ",00".

like image 626
Parth Bhanderi Avatar asked Jul 02 '19 11:07

Parth Bhanderi


People also ask

How do you change the cursor in TextField Flutter?

To change TextField cursor color in Flutter, simply add the cursorColor property and set the color of your choice.

How do you customize a TextField in Flutter?

By default, a TextField is decorated with an underline. You can add a label, icon, inline hint text, and error text by supplying an InputDecoration as the decoration property of the TextField . To remove the decoration entirely (including the underline and the space reserved for the label), set the decoration to null.


1 Answers

I've been having the same problem with setting a TextEditingController and this is what worked for me.

controller.text = someString; controller.selection = TextSelection.fromPosition(TextPosition(offset: controller.text.length)); 

TextSelection.fromPosition() does the following (from the documentation):

Creates a collapsed selection at the given text position. A collapsed selection starts and ends at the same offset, which means it contains zero characters but instead serves as an insertion point in the text.

like image 83
jwehrle Avatar answered Oct 05 '22 04:10

jwehrle