Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter How to handle text selection?

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.

like image 870
Serge Breusov Avatar asked Jun 27 '18 03:06

Serge Breusov


People also ask

How do you select text in Flutter?

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.

What is select handler in Flutter?

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.

How do you make text selectable in HTML in Flutter?

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.


1 Answers

You now have SelectableText() widget available

like image 59
Sebastian Avatar answered Oct 02 '22 15:10

Sebastian