Flutter inline widget sizing #601
matthew-carroll
started this conversation in
Investigations
Replies: 1 comment 1 reply
-
Would it be acceptable if the height constraint was the preferredLineHeight? It might be tough if you need the actual line height calculated after laying out all other content on the line. The size of the WidgetSpan itself would affect what ends up on each line. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Super Editor would like users to be able to insert bitmaps, GIFs, and other visuals within text (#8).
These inline widgets should respect the baseline and line height of the surrounding text content.
Does Flutter support such behavior?
WidgetSpans
Flutter provides
WidgetSpan
s, which display arbitrary widgets in the middle of text.WidgetSpan
s, support baseline alignment.However,
WidgetSpan
s don't support line-height constraints. TheWidgetSpan
constructor doc says "Child widgets heights are unconstrained...". This behavior is confirmed by inspectingRenderParagraph
, which is responsible for running layout for the inline widgets.From
RenderParagraph
:Custom spans?
If
WidgetSpan
s won't work, can we create our own specializedInlineSpan
?Super Editor could create a custom
InlineSpan
but it wouldn't have any effect on this problem. The root problem isRenderParagraph
, which hard-codes a decision to leave allPlaceholderSpan
s vertically unconstrained.Estimating height
Perhaps Super Editor could assign a height to a
WidgetSpan
with an approximation based on the incoming line height.Unfortunately, it doesn't look like a given
WidgetSpan
is notified of the incoming/preceding text style. One would expect to receive that information in theWidgetSpan
'sbuild()
method, but that information isn't provided.Conclusion
Super Editor can't impose line-height restrictions on inline widgets without implementing an alternative to
RenderParagraph
.Super Editor can't approximate a height by inspecting the preceding text style, because the preceding text style is not provided to a given
WidgetSpan
.At this time, the only control over inline widget height looks to be an explicit height that's chosen by the widget that's being displayed.
Beta Was this translation helpful? Give feedback.
All reactions