I need to display a styled text for reading and some actions. User should be able to select piece of text and mark it with color, save it or expand it (show an additional information, for example a translation to another language).
I can display text by using RichText widget.
1) How to make it selectable and how/where to add onTextSelected listener? There is a class TextSelection but I can't see how/where its used.
2) What is a simplest way to expand text? I can reload full text (with changes added) and totally update widget, but this will result to scrolling to the top of a text and I think there should be a better approach.
SelectableText Widget in Flutter allows the user to Select/Copy the content on the UI. The typical Text Widget in Flutter won't permit a copy/select element by double-tapping on the content, we can either select/copy the content. This widget displays a string of text with a single style.
This handler is invoked when the user either wants to change the currently selected text in a text field or change the position of the cursor. TalkBack users can trigger this handler by selecting "Move cursor to beginning/end" or "Select all" from the local context menu.
In Flutter, the text presented by the Text widget is undetectable (even on the web). To make text selectable, you can use the SelectableText widget.
You now have SelectableText()
widget available
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With