Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Detect end of the html content offset#1172

Unanswered
asmith20002 asked this question inQ&A
Discussion options

Is it possible to get the end offset of the content as shown below?

html_offset

I'd like to be able to insert a widget at the red/yellow dot. That's a thing CSS float can do easily but since float is not supported, I'd like to know if there's a way we could detect that offset to calculate the remaining space to the end of the line.

You must be logged in to vote

Replies: 5 comments

Comment options

As far as I'm aware, there isn't a simple way to get that offset without writing some sort of layout algorithm from scratch.Html uses theText.rich widget under the hood to lay everything out, which relies heavily on the Flutter engine's text layout algorithms which are deeply baked into the Flutter ecosystem. Basically this means that if you can do it with aText.rich widget, you can do it with theHtml widget.

You could possibly do some sort of hack withrtl text and aWidgetSpan to achieve something like this, but if you are just trying to put a child widget on the right side of theHtml widget, it would be a lot simpler just to use aStack and place whatever widget you want to down in that bottom right corner.

Some more info about what you are trying to achieve could help us provide some better workarounds!

You must be logged in to vote
0 replies
Comment options

Stack doesn't work in this situation because sometimes there is not enough space and the "float-right" widget should go to the next line.

Here's my original question in StackOverflow: (the image in the first post describes the situation)
https://stackoverflow.com/questions/70802737/flutter-chat-text-align-like-whatsapp-or-telegram

The answers on that question are suggestions using aRenderBox and they are usingTextPainter to paint the text and get its size. The problem is that those answers are assuming that I have plain text so theTextPainter is used to calculate the offset. I'm usingHtml() and I can't use theTextPainer to calculate the renderedHtml.

Knowing the remaining space on the last line ofHtml is key to this problem.

if (space is enough)
{
// UseStack()
}
else
{
// UseWrap()
}

You must be logged in to vote
0 replies
Comment options

Ah, thank you for the StackOverflow link. I wasn't super familiar withTextPainter, so that code sample gave me some insight. I'll need to play around with it for a little while, but I might be able to get something that works. The trick is going to be getting the PlaceholderDimensions of Widgets within the Html. I'll probably have to get some inspiration from theRichText widget. I'll keep you posted!

You must be logged in to vote
0 replies
Comment options

I wasn't home. Sorry for the late reply.

This is great news. Can't wait to see some sort of solution. Thanks for the effort, :)

You must be logged in to vote
0 replies
Comment options

Just wanted to follow up. Did you manage to play around with RichText? Any progress?

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@asmith20002@Sub6Resources

[8]ページ先頭

©2009-2025 Movatter.jp