Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the Highlight Color of selected text

Tags:

flutter

When the user select a text from inside a TextField, the default highlight color is blue. How to change it to green for example ?

enter image description here

enter image description here

enter image description here

like image 346
TSR Avatar asked Dec 11 '22 03:12

TSR


2 Answers

2021 answer

Wrap with Theme and use copyWith to preserve other theme data.

 Theme(data: Theme.of(context).copyWith(
   textSelectionTheme: TextSelectionThemeData(
     selectionColor: Colors.green)),
   child: TextFormField()
)
like image 116
Roddy R Avatar answered Jan 19 '23 04:01

Roddy R


Wrap your text widget with theme and assign the color to the textSelectionColor property inside ThemeData

refer below code for same:- I have changed the text selection color to green

 Theme(
     data: ThemeData(textSelectionColor: Colors.green),
          child: TextField(
              controller: _inputController,
              decoration: InputDecoration(hintText: "Input"),
           ),
  ),
like image 40
Shardul Singh Gurjar Avatar answered Jan 19 '23 05:01

Shardul Singh Gurjar