daohoangson / flutter_widget_from_html

Flutter package to render html as widgets that supports hyperlink, image, audio, video, iframe and many other tags.
https://pub.dev/packages/flutter_widget_from_html
MIT License
640 stars 240 forks source link

Texts should be selectable #102

Closed umutoney closed 2 years ago

umutoney commented 5 years ago

https://master-api.flutter.dev/flutter/material/SelectableText-class.html

daohoangson commented 5 years ago

Selectable text is very useful but unfortunately it cannot be done with SelectableText.rich because it does not support non-TextSpan children which is used by this plugin to render inline image.

https://api.flutter.dev/flutter/material/SelectableText/SelectableText.rich.html

The textSpan parameter must not be null and only contain TextSpan in textSpan.children. Other type of InlineSpan is not allowed.

daohoangson commented 5 years ago

Reconsider SelectableText support when this issue is closed: https://github.com/flutter/flutter/issues/38474

JsonLinesCode commented 3 years ago

You could use https://github.com/fluttercandies/extended_text

daohoangson commented 3 years ago

https://github.com/flutter/flutter/issues/38474#issuecomment-862130308

SelectableText is actually built on top of EditableText internally, which means that the core WidgetSpan support added for flutter/flutter#30688 which landed in flutter/flutter#83537 may have also allowed SelectableText to support WidgetSpans. I will check if this is indeed true.

If anyone has a particular use case, please try passing WidgetSpans to the SelectableText.rich() constructor and see if it behaves as you expect.

Wow 🤯

daohoangson commented 3 years ago

It works!

JsonLinesCode commented 3 years ago

Does this mean that we'll have selectable text on flutter_html_widget ? 🤩

daohoangson commented 3 years ago

Does this mean that we'll have selectable text on flutter_html_widget ? 🤩

Yes 🚀

DFelten commented 3 years ago

Great to hear that this feature will be possible in the future. Can you give an estimation how well it works? 😃

Currently we have to create a div tag with a custom class and da widget factory for coupons to make them copyable.

daohoangson commented 3 years ago

Current it works with simple test cases and doesn't with HTML that has deep nested stylings. I ran a few quick tests so I didn't dig any further. Once the bugs are ironed out, I think it should be fairly stable.

rajeshzmoke commented 3 years ago

@daohoangson Any update on this?

daohoangson commented 3 years ago

The reference commits haven't reached stable yet. They are in beta though, that's some progress.

daohoangson commented 3 years ago

Flutter 2.5 has been released with support for WidgetSpan in SelectableText. Expect a new version soon.

daohoangson commented 3 years ago

It works on stable but Flutter source code modification is still required. The assertion should be removed sometime soon (I hope). Will keep a close eye on this.

bksubhuti commented 3 years ago

This is very important to me. I'm glad to hear about the progress. Is there special code to write to make this happen. I'm confused when a different widget (SelectableText.rich) is mentioned, unless that is used internally in wrapped code.?

daohoangson commented 3 years ago

Very simple tests have been done to verify selectable widget but it's not usable yet. We will have to wait.

bksubhuti commented 3 years ago

What is the approximate time projection for this feature?

daohoangson commented 3 years ago

It depends entirely on the Flutter team, I'm asking at https://github.com/flutter/flutter/issues/38474#issuecomment-932849890.

daohoangson commented 3 years ago

The Flutter team has removed the restriction on master channel, it should make it way to dev channel in a few days.

JesseBlackman commented 2 years ago

The Flutter team has removed the restriction on master channel, it should make it way to dev channel in a few days.

hi, still waiting for support

arianneorpilla commented 2 years ago

I am also pretty excited to finally be able to have this -- I tried passing paragraphs to use SelectableText and while I can't select separate paragraphs, it's really promising to just see this finally work on master. Is there a fork of the package with the text with factories already set up to have SelectableText I can try out?

daohoangson commented 2 years ago

Looks like it's available in the 2.8.0 beta 3 days ago https://github.com/flutter/flutter/releases/tag/2.8.0-3.1.pre, let me release a new version with this real quick.

daohoangson commented 2 years ago

v0.8.3-beta.1 has been released. The new parameter works like this:

HtmlWidget(
  html,
  isSelectable: true, // default is false
)

There is a live demo link available in the PR: https://github.com/daohoangson/flutter_widget_from_html/pull/631. There are still issues like selecting across multiple paragraphs etc.

DFelten commented 2 years ago

Thanks for this! I will test this tomorrow. Which version or branch of Flutter do we need for this?

daohoangson commented 2 years ago

You need at least 2.7, currently in beta channel.

bksubhuti commented 2 years ago

Is there a way to have the popup disabled and also a callback when there is a selection? and special wish is to have a callback on word click (as if every word were a url).

Our webview project does this.. https://play.google.com/store/apps/details?id=com.paauk.tipitakapalireader We want to migrate out of webview and into this package so we can do desktop.

daohoangson commented 2 years ago

You want to disable the selectable popup? Err, you can disable selectable mode for that I guess.

Technically you can register all sort of gesture recognizer on the widgets and texts. But doing so for everything may hurt performance 🤔 Please open a separate discussion for this if you want to discuss further.

daohoangson commented 2 years ago

v0.8.3+1 has been released with support for isSelectable in the flutter_widget_from_html package. The core package is not updated at this time to avoid bumping the minimum required Flutter version. v2.8 stable is pretty new.

I'm closing this two-year-old issue right now, please open new issue if you encounter bugs related to this feature.

MorelSerge commented 2 years ago

Can this be augmented with the newly released SelectionArea in Flutter 3.3? Makes selecting multiple paragraphs possible!

daohoangson commented 2 years ago

Should be. I'm working on it here https://github.com/daohoangson/flutter_widget_from_html/pull/821. Ideally HtmlWidget should work automatically if it is built within a selection area.

bksubhuti commented 2 years ago

okay.. sadhu x 3 (appreciated). Because of you, we moved forward to 5 OS.