You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
The hit area of the widget is currently suboptimal. The problem occurs when there is text with multiple blank lines in between. In this situation, the widget will continue to respond to hit events even if the user taps in those blank spaces. In the image below, you can see the region that is mistakenly identified as a hit target colored green. In my opinion, the widget should only detect a hit event when the user taps on the text with the background, which is below colored in amber.
Describe the solution you'd like
We should override the hitTest method of the CustomPainter inside the RoundedBackgroundTextPainter class. Below is a simple example of how to do this.
@overridebool?hitTest(Offset position) {
// Retrieve the line informationfinal lineInfos =computeLines(text);
// Check each linefor (final lineInfo in lineInfos) {
for (final info in lineInfo) {
// Construct the rounded rectangle for this linefinal rRect =RRect.fromLTRBR(
info.x,
info.y,
info.fullWidth,
info.fullHeight,
Radius.circular(info.outerRadius(outerRadius)),
);
// Check if the position is within this rectangleif (rRect.contains(position)) {
onHitTestResult(true); // Call method with the result for external handlingreturntrue;
}
}
}
// If the position was not within any line's bounding boxonHitTestResult(false); // Call method with the result for external handlingreturnfalse;
}
This example is simple and will not perfectly detect any inner rounding. It will also not detect the surrounding padding.
Maybe you have a better solution, but I think for most cases this simple hit detection will be enough. For me it will also be useful if it always calls a method like onHitTestResult which returns if the hitTest is true or false. This is helpful for applications that have more complex logic with many layers. So in the end the widget will look like this then.
Is your feature request related to a problem? Please describe.
The hit area of the widget is currently suboptimal. The problem occurs when there is text with multiple blank lines in between. In this situation, the widget will continue to respond to hit events even if the user taps in those blank spaces. In the image below, you can see the region that is mistakenly identified as a hit target colored green. In my opinion, the widget should only detect a hit event when the user taps on the text with the background, which is below colored in amber.
Describe the solution you'd like
We should override the
hitTest
method of theCustomPainter
inside theRoundedBackgroundTextPainter
class. Below is a simple example of how to do this.This example is simple and will not perfectly detect any inner rounding. It will also not detect the surrounding padding.
Maybe you have a better solution, but I think for most cases this simple hit detection will be enough. For me it will also be useful if it always calls a method like
onHitTestResult
which returns if the hitTest is true or false. This is helpful for applications that have more complex logic with many layers. So in the end the widget will look like this then.The text was updated successfully, but these errors were encountered: