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.8k stars 874 forks source link

[FEATURE] Handling width-height with percentage #1185

Open mirkancal opened 2 years ago

mirkancal commented 2 years ago

Describe your feature request I see that flutter_html_iframe tries to parse width and height but fails when it contains "%". I think this kind of width and height values can use MediaQuery.of(context.buildContext).size.height or width.

Here's my "not so clean at the moment" solution for it.

 final num? isPercentWidthValue =
          context.tree.element?.attributes['width']?.contains('%') ?? false
              ? double.tryParse(context.tree.element?.attributes['width']!
                      .replaceAll('%', '') ??
                  '')
              : null;
 return Container(
   width: isPercentWidthValue != null
            ? MediaQuery.of(context.buildContext).size.width *
                isPercentWidthValue /
                100
            : givenWidth ?? (givenHeight ?? 150) * 2,
            ...

Let me know what you guys think.

Additional context

A picture of a cute animal (not mandatory but encouraged)