Flutter_html: In 1.0.0, shrinkWrap: true does not provide a size to the layout engine

Created on 13 May 2020  路  4Comments  路  Source: Sub6Resources/flutter_html

This is an issue when using shrinkWrapped Html widgets inside rows. On 1.0.0-pre.1 the element would have the size of its contents and get rendered properly.

For instance, this:

Row(
  children: [
    Html(data: 'Hello', shrinkWrap: true),
    Text(' world'),
  ]
)

Throws The following assertion was thrown during performLayout(): BoxConstraints forces an infinite width.

Most helpful comment

@red42 it helped me:

style: {
        "html": Style(
          display: Display.INLINE,
        ),
        "body": Style(
          display: Display.INLINE,
        ),
       "...": Style(
          display: Display.INLINE,
        ),
}

All 4 comments

Maybe this should not return double.infinity width for shrinkWrapped elements? It does solve the issue in my use cases, but I'm not sure it won't break other use cases.

class StyledText extends StatelessWidget {
  final InlineSpan textSpan;
  final Style style;

  const StyledText({
    this.textSpan,
    this.style,
  });

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width:
          style.display == Display.BLOCK || style.display == Display.LIST_ITEM
              ? double.infinity
              : null,
      child: Text.rich(
        textSpan,
        style: style.generateTextStyle(),
        textAlign: style.textAlign,
        textDirection: style.direction,
      ),
    );
  }
}

Relevant code

This has completely broken shrinkWrap. Any chance we can get this fixed?

@red42 it helped me:

style: {
        "html": Style(
          display: Display.INLINE,
        ),
        "body": Style(
          display: Display.INLINE,
        ),
       "...": Style(
          display: Display.INLINE,
        ),
}

@red42 it helped me:

style: {
        "html": Style(
          display: Display.INLINE,
        ),
        "body": Style(
          display: Display.INLINE,
        ),
       "...": Style(
          display: Display.INLINE,
        ),
}

This worked for me .. but the issue should be solved ASAP

Was this page helpful?
0 / 5 - 0 ratings

Related issues

freddoOswaldo picture freddoOswaldo  路  4Comments

robert-virkus picture robert-virkus  路  3Comments

andokai picture andokai  路  3Comments

ngaurav picture ngaurav  路  6Comments

NicoDreamzZ picture NicoDreamzZ  路  5Comments