Skip to content

InlineText's GestureDetector is always full-width #131435

Closed

Description

@justinmc

Is there an existing issue for this?

Steps to reproduce

  1. Create a TextSpan with a recognizer property, or use the app below.
  2. Run the app on a platform with a mouse.
  3. Hover over the space to the right of the TextSpan.

Expected results

Only "example.com" is tappable, as in a typical link on the web, for example. Here I've highlighted the area I expect to be tappable in blue (with an image editor, not with Flutter).

Screenshot from 2023-07-27 12-59-33-small

Actual results

The entire width, highlighted in blue, is tappable.

Screenshot from 2023-07-27 12-59-33

Related:
#27293
#13211
#125927

Code sample

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

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RichText(
              text: TextSpan(
                style: const TextStyle(
                  color: Colors.black,
                ),
                text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ',
                children: [
                  TextSpan(
                    text: 'example.com',
                    style: const TextStyle(
                      color: Colors.blue,
                    ),
                    recognizer: TapGestureRecognizer()..onTap = () {},
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

Logs

No response

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel master, 3.13.0-10.0.pre.49, on Debian GNU/Linux rodete 6.3.7-1rodete2-amd64, locale en_US.UTF-8)
    ! Upstream repository [email protected]:justinmc/flutter.git is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to [email protected]:justinmc/flutter.git to dismiss this error.
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2021.3)
[✓] Android Studio (version 2022.2)
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 1 category.

Activity

  1. added
    a: text inputEntering text in a text field or keyboard related problems
    P2Important issues not at the top of the work list
    on Jul 27, 2023
  2. justinmc commented on Jul 27, 2023

    @justinmc
    ContributorAuthor

    @LongCatIsLooong mentioned that there is a new Skia API that could affect this. Seems to be related to the hit test method of the TextSpan.

  3. justinmc commented on Aug 3, 2023

    @justinmc
    ContributorAuthor

    I should check if this issue is fixed after #131640 is merged.

  4. dutsky commented on Aug 9, 2023

    @dutsky

    I have same issue, and I'm sorry, do you know any workarounds, maybe? The only I had found is to add space character as children of TextSpan with recognizer. Something like that:

    TextSpan(
      text: text,
      recognizer: _recognizer,
      children: [TextSpan(text: ' ')],
    );
  5. justinmc commented on Aug 9, 2023

    @justinmc
    ContributorAuthor

    I verified that #131640 does fix this problem! It was closed while waiting for a new Skia API, but the plan is to reopen it again after that.

  6. justinmc commented on Aug 9, 2023

    @justinmc
    ContributorAuthor

    @dutsky You could patch that PR into a local copy of Flutter if you really need a fix now. Otherwise I'm not aware of any workarounds.

  7. letungcntt commented on Aug 23, 2023

    @letungcntt

    @justinmc Now, my project used flutter 3.7 how to fix it. I don't update because lib has crash with 3.10 or 3.13

  8. justinmc commented on Aug 24, 2023

    @justinmc
    ContributorAuthor

    @letungcntt How is this causing a crash? Are you able to post a minimal reproduction example?

    I don't think there is a workaround until #131640 is merged, see #131640 (comment).

    CC @LongCatIsLooong

  9. github-actions commented on Jan 3, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions