Skip to content

Web: GestureRecognizers in nested TextSpans do not work. #34931

@kwight

Description

@kwight

If I have nested TextSpans in a RichText widget, adding a GestureRecognizer to the top level TextSpan will work fine, but adding one to a nested TextSpan will not. This is only an issue with Flutter for web, not standard Flutter.

This works:

RichText(
  text: TextSpan(
    text: 'TOP',
    recognizer: TapGestureRecognizer()..onTap = _incrementCounter,
    children: <TextSpan>[
      TextSpan(
        text: 'CHILD',
        // recognizer: TapGestureRecognizer()..onTap = _incrementCounter,
      ),
    ],
  ),
),

This does not:

RichText(
  text: TextSpan(
    text: 'TOP',
    // recognizer: TapGestureRecognizer()..onTap = _incrementCounter,
    children: <TextSpan>[
      TextSpan(
        text: 'CHILD',
        recognizer: TapGestureRecognizer()..onTap = _incrementCounter,
      ),
    ],
  ),
),

If both are present, the parent will win (I assume this is intended behaviour).

My use-case is nested spans to be able to colour separators in a slide credit, where I need different links. Or maybe I don't understand how best to work with RichText and TextSpan for something like this?

Screen Shot 2019-06-22 at 1 18 01 PM

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions