How do I make a TextSpan ripple when I tap it?

Viewed 6104

Imagine I have a long piece of text like this: HELLO THIS IS MY LONG SENTENCE . I want the word LONG to ripple (ink splash) when I tap it.

Let's say I have this code:

new RichText(
  text: new TextSpan(
    text: 'HELLO THIS IS MY ',
    style: DefaultTextStyle.of(context).style,
    children: <TextSpan>[
      new TextSpan(text: 'LONG', style: new TextStyle(fontWeight: FontWeight.bold)),
      new TextSpan(text: ' SENTENCE'),
    ],
  ),
)

Thanks!

3 Answers

By 2019, we can use this:

RichText(
  textAlign: TextAlign.center,
  text: TextSpan(
    style: textTheme.bodyText2,
    text: "HELLO THIS IS MY",
    children: [
      WidgetSpan(
        child: InkWell(
          onTap: () {},
          child: Text(
            "SENTENCE",
            style: TextStyle(color: colorScheme.primary),
          ),
        ),
      ),
    ],
  ),
),
Related