0
votes

I am displaying a text in a card, I want to add long click functionality to display more info about selected word ( the word that is long clicked ). Which text widget supports it? SelectableText widget is not suitable, because it gives user ability to copy all of my text to somewhere else, I don't like it, I just want to find out which word is selected so I display it's meaning.

Currently I am using Html widget which apparently doesn't support long pressed word.

1
GestureDetector has onLongPressStart property so you can get the location where you "long "pressed, now you can use Paragraph API to find the position in your text closest to the given location - pskink
So I use which Widget type to display text that supports Paragraph API? - AVEbrahimi
RichText widget, and use RenderParagraph api, not Paragraph as I said before - pskink
update: with Text it works too - Text uses RenderParagraph as its RenderObject as well - pskink
I am sort of newbie, how can I find which word is at Offset of a RichText - AVEbrahimi

1 Answers

-1
votes

You can wrap your Text widget with GestureDetector which has onLongPressed method.

body: Center(
        child: Card(
          child: GestureDetector(
            child: Text('Long press'),
            onLongPress: () {
              // your code here
            },
          )
        )
      )

Hope this answers your question.