flutter_widget_from_html icon indicating copy to clipboard operation
flutter_widget_from_html copied to clipboard

Possibility of extracting a `TextSpan` out of a text-only HTML?

Open kekland opened this issue 1 year ago • 3 comments

Use case

Hi! Thanks for this amazing project, really saved us from a hassle of building an HTML parser :)

We have a use-case where we need to render a HTML text coming from the server as a TextSpan, so that we can insert it in a Text.rich() alongside other TextSpans. It's guaranteed from the server that the HTML text is a single paragraph containing only <b>, <i>, and <u> tags.

After looking through the library, I couldn't find an easy way to achieve this.

Proposal

Add an easy way to create a TextSpan from a BuildTree, instead of a full widget

kekland avatar Sep 06 '24 12:09 kekland

The internal logic will build the TextSpan as needed. Can't you use HtmlWidget directly?

daohoangson avatar Sep 11 '24 16:09 daohoangson

We're currently building a UI where it's important to know the per-line metrics for the text. Currently I'm doing this via TextPainter and passing the TextSpan to it. Now we want to add HTML support for the text that comes from the backend, which is guaranteed to be a single paragraph. We also add some other children to this textspan.

I can't use HtmlWidget directly since it'll build the text internally, so I can't attach to its text painter. I wanted to somehow be able to use the internal logic so that I can build just the TextSpan.

kekland avatar Sep 13 '24 10:09 kekland

With enough inputs, I think it's possible to make the TextSpan builder logic independent. Maybe.

daohoangson avatar Sep 29 '24 11:09 daohoangson