-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Fix SelectableText only supports TextSpan exception for Flutter 2 #80
Conversation
@Cretezy will this be merged? |
Thanks for this fix, I had to use this PR's fork in my project to solve the associated exception, waiting for it to be merged. |
lib/flutter_linkify.dart
Outdated
required MouseCursor mouseCursor, | ||
required InlineSpan inlineSpan, | ||
}) : super( | ||
child: MouseRegion( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we would like to keep MouseRegion
support for the non-selecting use-case.
I think having SelectableLinkify
pass an argument to buildTextSpan
to not use MouseRegion
would be a better implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Cretezy
Unfortunately adding LinkableSpan
class as a wrapper to support MouseRegion
will result in throwing the following error for anyone who uses flutter 2
"SelectableText only supports TextSpan; Other types of InlineSpan is not allowed"
Prior Flutter 2 the selectable_text.dart class was declaring the rich text inside the class as dynamic type, but after flutter 2 the type was enforced to be TextSpan that's why the assertion is throwing an error.
on line 230 inside selectable_text.dart file after Flutter 2.0
const SelectableText.rich(
TextSpan this.textSpan, {
Key? key,
this.focusNode,
this.style,
this.strutStyle,
on line 253 inside selectable_text.dart file before Flutter 2
const SelectableText.rich(
this.textSpan, {
Key key,
this.focusNode,
this.style,
this.strutStyle,
So we can't use WidgetSpan to enable using the MouseRegion property.
There is a merge request on Flutter repo for letting the TextSpan widget support mouseCursor and it was accepted but it was merged on the master channel only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you misunderstood me.
When rendering Linkify
, we can use mouse regions, therefore we should. When rendering SelectableLinkify
, we can't use mouse regions, therefore we shouldn't.
The argument should toggle between using mouse regions and not. Linkify
should have it as true
while SelectableLinkify
should have it as false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the misunderstanding.
I have updated the pull request, please review the updates.
…SelectableLinkify using useMouseRegion flag inside buildTextSpan
Thank you, just released 5.0.2 with this change! |
Not much changed, Thanks for your hard work on this package anyway <3