fluttertextthemestextfieldselected

Flutter - Change color of selected text in a Textfield


I have a Searchbar and due to my app theming, the text inside becomes hard to read when its selected. I would like to know if there is a way to set a different text color when it's selected.

Searchbar

Thanks in advance!


Solution

  • Flutter does not support changing the selected text color via the theme declaration in the main widget, only can change background color. You must use the SelectableText in each input style property, like as:

    SelectableText(
        'Example text',
        style: TextStyle(color: Colors.red), // Yout text color on selected
    )
    

    Reference: https://github.com/flutter/flutter/issues/99231