Search code examples
flutterdartcontrollerselectiononchange

There isn’t a setter named 'selection' in class 'TextEditingController'


I'm try to keep the cursor on the right of the TextField input using the 'controller.selection' line with 'onChange' as shown below; but getting an error

onChanged: (text) {
_myController.text = text;
_myController.selection = TextSelection.fromPosition(TextPosition(offset: 
_myController.text.length));
},     

the error:

There isn’t a setter named 'selection' in class 'TextEditingController'.
Try correcting the name to reference an existing setter, or declare the setter.

I have used this method before with no issues but for some reason getting this now.


Solution

  • It has been solved by force upgrading the flutter sdk using flutter upgrade --force - before that it was not upgrading for some reason.

    Probably I modified some system file or library that I was not supposed to modify, but now everything seems to be fine back to normal.