Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.76k stars 814 forks source link

Table nested Table issue[BUG] #917

Closed AceChen1 closed 1 year ago

AceChen1 commented 2 years ago

hi guys, if the html data like that:


const htmlData = r"""
<table><tbody><tr><td><table><tbody><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr></tbody></table><br></td></tr></tbody></table>
""";

looks like the lib will have issue, can help to give a suggestion if have those case ?

tneotia commented 2 years ago

Duplicate of #589

AceChen1 commented 2 years ago

Duplicate of #589

oh? looks like this lib is also you created wo

AceChen1 commented 2 years ago

Duplicate of #589

looks like the issue still no solution so far ?

tneotia commented 2 years ago

looks like this lib is also you created wo

Haha no I didn't create it, but I am a contributor here.

looks like the issue still no solution so far ?

For now yes, the table rendering is quite tricky in Flutter, you can see we have tried to discuss solutions in that issue. Hopefully we can find something soon.

AceChen1 commented 2 years ago

looks like this lib is also you created wo

Haha no I didn't create it, but I am a contributor here.

looks like the issue still no solution so far ?

For now yes, the table rendering is quite tricky in Flutter, you can see we have tried to discuss solutions in that issue. Hopefully we can find something soon.

I see, i just try your way, i found at least it will not cause error, may i know your guys new version will include this code? for us app meet this issue so far, need find a way to avoid the issue but don't want change the code on us local side...

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)),
    );
tneotia commented 2 years ago

I see, i just try your way, i found at least it will not cause error, may i know your guys new version will include this code? for us app meet this issue so far, need find a way to avoid the issue but don't want change the code on us local side...

The problem with this is that if the table is nested inside other tag, like td > div > table, then this will error once again. Of course this might be a quick fix for the common use case, but we shouldn't release this as a full fix because it does not work for all HTML. I suggest forking the package, adding this code, and making git dependency on this fork if you don't want to change locally.

AceChen1 commented 2 years ago

I see, i just try your way, i found at least it will not cause error, may i know your guys new version will include this code? for us app meet this issue so far, need find a way to avoid the issue but don't want change the code on us local side...

The problem with this is that if the table is nested inside other tag, like td > div > table, then this will error once again. Of course this might be a quick fix for the common use case, but we shouldn't release this as a full fix because it does not work for all HTML. I suggest forking the package, adding this code, and making git dependency on this fork if you don't want to change locally.

i see, thanks.

AceChen1 commented 2 years ago

@tneotia hi, may i know the master branch is the latest code? i just see the flutter pub, the latest version is 2.2.0, but looks like the master version is 2.1.5 (check from yaml file).

erickok commented 2 years ago

Master branch is normally latest but right now we are still waiting in the library owner to merge the 2.2.0 PR.

AceChen1 commented 2 years ago

Master branch is normally latest but right now we are still waiting in the library owner to merge the 2.2.0 PR.

i see, Thanks your update.

timmyrosen commented 2 years ago
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)),
    );

@AceChen1 @tneotia If I also wanted to implement this solution, where am I supposed to place this code? Where does element come from?

AceChen1 commented 2 years ago
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)),
    );

@AceChen1 @tneotia If I also wanted to implement this solution, where am I supposed to place this code? Where does element come from?

@timmyrosen hi guys, please use this repo, Thanks. https://github.com/Jim-S-Chang/flutter_html

erickok commented 2 years ago

I understand why this is working for you (https://github.com/Jim-S-Chang/flutter_html/commit/dd25f9a1432b7cde56eed20e220c6b8546ad76c8) but it's too limited I'm afraid as it might not be the direct parent of the nested table that is a <td>. I guess if we can search recursively though that it would be sufficient to support nested tables. I'll give it a shot.

danielgchap commented 2 years ago

@AceChen1 Hi brother, do you have an email I can hit you up on. I am trying to implement your fix in my code for a nested table and struggling a bit. I'd really appreciate it! danielgchap@hotmail.com Appreciate you!

danielgchap commented 2 years ago

@erickok @AceChen1 This is what I'm working with.. any thoughts...?

If I remove the in front and behind the embedded table, it displays in the app. Otherwise, no. Would love your help and input...

Screen Shot 2022-02-02 at 11 19 38 AM

Thank you!

erickok commented 1 year ago

Closing this as it really is a duplicate of #589. See the discussion there for more info.