Skip to content
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

Merged
merged 5 commits into from
Apr 13, 2021

Conversation

MohamedEL-Torky
Copy link
Contributor

Not much changed, Thanks for your hard work on this package anyway <3

@CLAassistant
Copy link

CLAassistant commented Mar 8, 2021

CLA assistant check
All committers have signed the CLA.

@bsneider
Copy link

bsneider commented Apr 7, 2021

@Cretezy will this be merged?

@pr-Mais
Copy link

pr-Mais commented Apr 11, 2021

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.

required MouseCursor mouseCursor,
required InlineSpan inlineSpan,
}) : super(
child: MouseRegion(
Copy link
Owner

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.

Copy link
Contributor Author

@MohamedEL-Torky MohamedEL-Torky Apr 12, 2021

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.

flutter/flutter#77754

Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cretezy

Sorry for the misunderstanding.
I have updated the pull request, please review the updates.

@Cretezy Cretezy merged commit 201e147 into Cretezy:master Apr 13, 2021
@Cretezy
Copy link
Owner

Cretezy commented Apr 13, 2021

Thank you, just released 5.0.2 with this change!

ooglek added a commit to ooglek/flutter_linkify that referenced this pull request Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants