flutter_html icon indicating copy to clipboard operation
flutter_html copied to clipboard

[caution] table nested is not supported : )

Open dreamer2q opened this issue 3 years ago • 10 comments

As the title points out, flutter_html won't support table nesting.

And I do not know how to solve it.

dreamer2q avatar Mar 20 '21 13:03 dreamer2q

Without looking into this, I guess flutter_layout_grid doesn't support nested tables. I'm not sure why the necessarily is so, though.

erickok avatar Mar 20 '21 21:03 erickok

Hmm actually flutter_layout_grid support it just fine. I am not sure where you got this error, but in my test the only reason this doesn't work (on master branch) is because of we try to determine via LayoutBuilder if the table is in a horizontally unbounded or bounded widget, but then LayoutBuilder does not support returning intrinsic dimensions. Needs more investigation.

erickok avatar Apr 10 '21 14:04 erickok

Is there a reason for using the LayoutBuilder? For me, tables just render fine when removing it...

derolf avatar Apr 19 '21 14:04 derolf

Yes, it is used to determine if the table is in a bounded layout. Because if it is in an unbounded layout we cant support percentage based column sizes and have to set different column constraints accordingly.

I have tried to find a solution but failed so far.

erickok avatar Apr 19 '21 17:04 erickok

I experimented with this a little. It seems the nested table is the one that throws the error. Here's something I tried that worked:

bool hasTable = element?.parent?.localName == 'td';
    return Container(
      margin: style.margin,
      padding: style.padding,
      decoration: BoxDecoration(
        color: style.backgroundColor,
        border: style.border,
      ),
      width: style.width,
      height: style.height,
      child: hasTable ? _layoutCells(context, null)
          : LayoutBuilder(builder: (_, constraints) => _layoutCells(context, constraints)),
    );

and change !constraints?.hasBoundedWidth to !(constraints?.hasBoundedWidth ?? false) so BoxConstraints can be null.

Of course, this doesn't work if the tree is, say td > div > table, but its a start. Maybe something like this can be used to solve this issue?

tneotia avatar Apr 26 '21 19:04 tneotia

Hmm maybe. The problem we have here is that to know if we can use percentage-based column widths, I need to know ifd 'we' are in a horizontally bounded container or not. I was using LayoutBuilder for this purpose but indeed it breaks (among other things) embedded tables.

If anyone knows a better way to determine if at that spot we are in a horizontally bounded layout or not, that would solve the source problem.

erickok avatar Apr 27 '21 11:04 erickok

I fear that’s impossible in the “Widget”-world, you need to do it in the “RenderBox”-world afaik.

derolf avatar Apr 27 '21 11:04 derolf

Yes, I agree. And I am not feeling very at my place yet there. I should give it a try though.

erickok avatar Apr 27 '21 13:04 erickok

any solution for this?

sumitbhanushali avatar May 31 '21 05:05 sumitbhanushali

Sorry, not at the moment. I tried again yesterday and couldn't come up with a solution yet. Will have to read more about flutter and come back to this.

erickok avatar Jun 01 '21 07:06 erickok