Skip to content

[web]: TextSpan recognizer ignored when RichText wraps #39226

@idraper

Description

@idraper

flutter_web version: 2.5.0
browser: Chrome Version 76.0.3809.100 (Official Build) (64-bit)

When running webdev serve, I have a RichText's which are in a column, and the text wraps around (as desired). The problem I am facing is that if a child TextSpan has a recognizer, it is only triggered as long as the TextSpan is on the first line. Any text that is wrapped/overflowed, while visible and applies style correctly, does not register a tap.

I wrote an example script and ran it both using webdev serve as well as flutter run using an Android Emulator. The only modification was my headers and pubspec accordingly:

webdev version:

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

android version:

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

My full test code:

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(primarySwatch: Colors.blue,),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Center(
          child: Padding(
            padding: const EdgeInsets.only(left: 40.0 , right: 40.0),
            child: Align(
              alignment: Alignment.topCenter,
              child: Container(
                height: MediaQuery.of(context).size.height - 168,
                child: Foo(),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

class Foo extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Column(
          children: [
            Flexible(
              child: RichText(
                text: TextSpan(
                  style: Theme.of(context).textTheme.display1.copyWith(fontSize: 20),
                  children: [
                    TextSpan(
                      text: '"You have one minute and your minute has begun and no time will be added at the end, even to accommodate this sentence with all of it\'s baroque dependent clauses and cascading turns of phrase." - '
                    ),
                    TextSpan(
                      text: 'Andy Bernard',
                      recognizer: TapGestureRecognizer()..onTap = () => print ('pressed1'),
                    ),
                  ],
                ),
              ),
            ),
            Padding(padding: const EdgeInsets.only(bottom: 40),),
            Flexible(
              child: RichText(
                text: TextSpan(
                  style: Theme.of(context).textTheme.display1.copyWith(fontSize: 20),
                  children: [
                    TextSpan(
                      text: 'Andy Bernard - ',
                      recognizer: TapGestureRecognizer()..onTap = () => print ('pressed2'),
                    ),
                    TextSpan(
                      text: '"You have one minute and your minute has begun and no time will be added at the end, even to accommodate this sentence with all of it\'s baroque dependent clauses and cascading turns of phrase."'
                    ),
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

}

When using flutter web, pressed2 is printed but pressed1 is never printed. In contrast, the android build works as expected, printing each when they are tapped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: typographyText rendering, possibly libtxtframeworkflutter/packages/flutter repository. See also f: labels.platform-webWeb applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions