-
Notifications
You must be signed in to change notification settings - Fork 28.6k
GestureRecognizer on TextSpan takes up all remaining spaces of a line instead just over the TextSpan #43400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This happens because
This makes sense for positioning the caret in an editable text widget, but will be imprecise for hit testing the last span in non-editable text. |
I was able to reproduce this on latest sample code
flutter doctor -v
|
Did you find any solution? @ianloic @anaisbetts @sgraham @gmoothart @sethladd |
Appending a spacing TextSpan can fix this issue: TextSpan(
text: 'your text',
),
TextSpan(
// just append an spacing text
text: ' ',
), |
Still reproduces on the latest versions of flutter. recordingScreen.Recording.2022-12-01.at.11.14.56.movupdated sampleimport 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(
title: 'Navigation Basics',
home: Body(),
));
}
class Body extends StatelessWidget {
const Body({super.key});
@override
Widget build(BuildContext context) {
return Container(
color: Colors.black,
margin: const EdgeInsets.all(100),
child: RichText(
softWrap: true,
text: TextSpan(
children: <InlineSpan>[
const TextSpan(
text: "very_long_starting_text",
style: TextStyle(
color: Colors.red,
)
),
const TextSpan(
text: " ",
style: TextStyle(
color: Colors.green,
decoration: TextDecoration.lineThrough,
decorationThickness: 2,
)
),
TextSpan(
text: "trailing_text",
style: const TextStyle(
color: Colors.yellow,
),
recognizer: TapGestureRecognizer()
..onTap = () {
//distinguish between real external link & jiki link
print("clicked!");
},
)
],
)
),
);
}
} flutter doctor -v
|
Fixes #131435, #104594, #43400 Needs flutter/engine#48774 (to fix the web test failure). Currently the method we use for text span hit testing `TextPainter.getPositionForOffset` always returns the closest `TextPosition`, even when the given offset is far away from the text. The new TextPaintes method tells you the layout bounds (`width = letterspacing / 2 + x_advance + letterspacing / 2`, `height = font ascent + font descent`) of a character, the PR changes the hit testing implementation such that a TextSpan is only considered hit if the point-down event landed in one of it's character's layout bounds. Potential issues: 1. In theory since the text is baseline aligned, we should use the max ascent and max descent of each character to calculate the height of the text span's hit-test region, in case some characters in the span have to fall back to a different font, but that will be slower and it typically doesn't make a huge difference. This is a breaking change. It also introduces a new finder and a new method `WidgetTester.tapOnText`: `await tester.tapOnText('string to match')` for ease of migration.
Reverts #139717 Initiated by: LongCatIsLooong This change reverts the following previous change: Original Description: Fixes #131435, #104594, #43400 Needs flutter/engine#48774 (to fix the web test failure). Currently the method we use for text span hit testing `TextPainter.getPositionForOffset` always returns the closest `TextPosition`, even when the given offset is far away from the text. The new TextPaintes method tells you the layout bounds (`width = letterspacing / 2 + x_advance + letterspacing / 2`, `height = font ascent + font descent`) of a character, the PR changes the hit testing implementation such that a TextSpan is only considered hit if the point-down event landed in one of it's character's layout bounds. Potential issues: 1. In theory since the text is baseline aligned, we should use the max ascent and max descent of each character to calculate the height of the text span's hit-test region, in case some characters in the span have to fall back to a different font, but that will be slower and it typically doesn't make a huge difference. This is a breaking change. It also introduces a new finder and a new method `WidgetTester.tapOnText`: `await tester.tapOnText('string to match')` for ease of migration.
Fixes flutter#131435, flutter#104594, flutter#43400 Needs flutter/engine#48774 (to fix the web test failure). Currently the method we use for text span hit testing `TextPainter.getPositionForOffset` always returns the closest `TextPosition`, even when the given offset is far away from the text. The new TextPaintes method tells you the layout bounds (`width = letterspacing / 2 + x_advance + letterspacing / 2`, `height = font ascent + font descent`) of a character, the PR changes the hit testing implementation such that a TextSpan is only considered hit if the point-down event landed in one of it's character's layout bounds. Potential issues: 1. In theory since the text is baseline aligned, we should use the max ascent and max descent of each character to calculate the height of the text span's hit-test region, in case some characters in the span have to fall back to a different font, but that will be slower and it typically doesn't make a huge difference. This is a breaking change. It also introduces a new finder and a new method `WidgetTester.tapOnText`: `await tester.tapOnText('string to match')` for ease of migration.
Reverts flutter#139717 Initiated by: LongCatIsLooong This change reverts the following previous change: Original Description: Fixes flutter#131435, flutter#104594, flutter#43400 Needs flutter/engine#48774 (to fix the web test failure). Currently the method we use for text span hit testing `TextPainter.getPositionForOffset` always returns the closest `TextPosition`, even when the given offset is far away from the text. The new TextPaintes method tells you the layout bounds (`width = letterspacing / 2 + x_advance + letterspacing / 2`, `height = font ascent + font descent`) of a character, the PR changes the hit testing implementation such that a TextSpan is only considered hit if the point-down event landed in one of it's character's layout bounds. Potential issues: 1. In theory since the text is baseline aligned, we should use the max ascent and max descent of each character to calculate the height of the text span's hit-test region, in case some characters in the span have to fall back to a different font, but that will be slower and it typically doesn't make a huge difference. This is a breaking change. It also introduces a new finder and a new method `WidgetTester.tapOnText`: `await tester.tapOnText('string to match')` for ease of migration.
Fixes #131435, #104594, #43400 Currently the method we use for text span hit testing `TextPainter.getPositionForOffset` always returns the closest `TextPosition`, even when the given offset is far away from the text. The new TextPaintes method tells you the layout bounds `(width = letterspacing / 2 + x_advance + letterspacing / 2, height = font ascent + font descent)` of a character, the PR changes the hit testing implementation such that a TextSpan is only considered hit if the point-down event landed in one of its character's layout bounds. Potential issues: In theory since the text is baseline aligned, we should use the max ascent and max descent of each character to calculate the height of the text span's hit-test region, in case some characters in the span have to fall back to a different font, but that will be slower and it typically doesn't make a huge difference. This is a breaking change.
Fixed by #140621. |
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 |
produces the following effect
when click on the area after the yelllow "trailing_text"
"clicked!" is printed
flutter doctor -v
The text was updated successfully, but these errors were encountered: