I’d like to create a text field in Flutter where, when I select a portion of the text and press a button, only the selected part changes its color, for example, to red. Moreover, if another section of the text is selected and its color changes, the previous text’s style should be preserved.
My goal is to modify the colors of different portions of text within a text field in Flutter. What steps should I follow to achieve this?
2
Answers
How can I create this with the pub.dev/packages/extended_text_field ?
I believe the best way to go about doing this is by using
SelectableText.rich()
. This doesn’t let you edit the text the way aTextField
would; luckily you can make it editable using theextended_text_field
package.Here’s a working Flutter app that implements the highlighting capability you’ve described:
Here it is in action: