Skip to content

[web]: TextSpans interact with wrong TapGestureRecognizers  #63638

@monkeyswarm

Description

@monkeyswarm

Flutter: Channel master, 1.20.0-3.0.pre.11, on Mac OS X 10.15.6. running on Chrome 84.0.4147.125

When multiple TextSpans, are in a parent TextSpan, shown within a constrained container, TapGestureRecognizers do not respond correctly.

See code below. This displays three spans of text in a fixed-width container.

Repro: tap on each of the three spans
Expected: see log 'span 0 tapped', 'span 1 tapped', 'span 2 tapped'.
Actual: see log 'span 0 tapped' for all spans.

If the TapGestureRecognizer is not set for the first span, then none of the other TapGestureRecognizers fire.

If the container width constraint is removed, then it works ok, until the browser window is made small enough to enforce multiple lines, in which case the bug reappears.

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'TextSpan',
        home: Center(
            child: Container(
                width: 300,
                color: Color(0xFFDDDDDD),
                child: RichText(
                    text: TextSpan(children: [
                  TextSpan(
                      text: '[Lorem ipsum dolor sit amet, ]',
                      recognizer: TapGestureRecognizer()
                        ..onTap = () => print('span 0 tapped')
                  ),
                  TextSpan(
                      text: '[consectetur adipiscing elit, ]',
                      recognizer: TapGestureRecognizer()
                        ..onTap = () => print('span 1 tapped')),
                  TextSpan(
                      text: '[sed do eiusmod tempor incididunt]',
                      recognizer: TapGestureRecognizer()
                        ..onTap = () => print('span 2 tapped')),
                ])))));
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work lista: typographyText rendering, possibly libtxtcustomer: junecustomer: web10f: gesturesflutter/packages/flutter/gestures repository.f: material designflutter/packages/flutter/material repository.found in release: 1.20Found to occur in 1.20frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions