onTap and hoverStyle does not work in rare conditions
kaboc opened this issue · 1 comments
This appears to be an edge case that only occurs in the following conditions:
- A single matcher matches the entire text.
- Neither
style
normatchStyle
is set.
Reproducible code
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: CustomText(
'abc@example.com',
definitions: [
TextDefinition(
matcher: const EmailMatcher(),
hoverStyle: TextStyle(color: Colors.blue),
onTap: (_) => print('Tapped'),
),
],
),
),
),
);
}
}
Expected behaviour
- The email address is shown in blue while the mouse pointer hovers over it.
- "Tapped" is printed in the console when the email address is tapped.
Actual behaviour
- The text only sits on the screen like the normal
Text
widget, with no colour change and no output to the console.
flutter_custom_text/lib/src/text.dart
Lines 233 to 237 in 7155620
When parsing is done and a single matcher has matched the entire text, the inner TextSpan
is replaced but still with the same text. It seems that the TextSpan
is considered to be unchanged because of the same text and therefore the added parameters are not used.
While the text is still being parsed:
Text.rich(
TextSpan(
children: [
TextSpan(
text: widget.text,
),
] ,
),
)
After the parsing is done:
Text.rich(
TextSpan(
children: [
TextSpan(
text: widget.text,
hoverStyle: xxxxxx,
onTap: xxxxxx,
),
] ,
),
)
Although I'm not sure exactly why just setting style
or matchStyle
prevents the issue, probably it somehow makes Flutter/Dart aware that the TextSpan
has been replaced and causes hoverStyle
and onTap
to become active.