like i have an edit profile page and inside text form field i populate textform field with existing data but when i press on that textform field i want my cursor to start from the last index of my pre loaded data but the keyboard cursor moves to starting point is there a way to achieve this.
this is my text form field
TextFormField(
decoration:
const InputDecoration(hintText: "First Name"),
validator: (value) {
if (value == null || value.isEmpty) {
return "Please enter your first name";
} else {
return null;
}
},
onChanged: (value) {
firstName = firstNameController.text;
if (firstName.isNotEmpty) {
firstName =
"${firstName[0].toUpperCase()}${firstName.substring(1)}";
firstNameController.selection =
TextSelection.fromPosition(
TextPosition(offset: firstName.length));
}
},
controller: firstNameController..text = firstName,
),
i am able to populate data inside textform field but the problem is when i press on textformfield i want my keyboard starting point to be at the last index of this populated data but keyboard cursor moves to the starting point no matter what need some help here thanks.
CodePudding user response:
You can use selection like this
firstNameController.selection = TextSelection.fromPosition(
TextPosition(
offset: firstNameController.text.length));