Skip to content

Commit 426c85d

Browse files
committed
Update documentation and clean up code
1 parent bec5d84 commit 426c85d

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ A Flutter widget for rendering HTML and CSS as Flutter widgets.
8686
- [SVG](#svg)
8787

8888
- [Table](#table)
89+
90+
- [Notes](#notes)
8991

9092
- [Migration Guide](#migration-guides)
9193

@@ -102,12 +104,13 @@ Add the following to your `pubspec.yaml` file:
102104
| | | | | | | | | | | |
103105
|------------|-----------|-------|-------------|---------|---------|-------|------|--------|--------|--------|
104106
|`a` | `abbr` | `acronym`| `address` | `article`| `aside` | `audio`| `b` | `bdi` | `bdo` | `big` |
105-
|`blockquote`| `body` | `br` | `caption` | `cite` | `code` | `data`| `dd` | `del` | `dfn` | `div` |
106-
|`dl` | `dt` | `em` | `figcaption`| `figure`| `footer`| `h1` | `h2` | `h3` | `h4` | `h5` |
107-
|`h6` | `header` | `hr` | `i` | `iframe`| `img` | `ins` | `kbd`| `li` | `main` | `mark` |
108-
|`nav` | `noscript`|`ol` | `p` | `pre` | `q` | `rp` | `rt` | `ruby` | `s` |`samp` |
109-
|`section` | `small` | `span`| `strike` | `strong`| `sub` | `sup` | `svg`| `table`| `tbody`| `td` |
110-
| `template` | `tfoot` | `th` | `thead` |`time` | `tr` | `tt` | `u` | `ul` | `var` | `video`|
107+
|`blockquote`| `body` | `br` | `caption` | `cite` | `code` | `data`| `dd` | `del` | `details` | `dfn` |
108+
| `div` | `dl` | `dt` | `em` | `figcaption`| `figure`| `footer`| `h1` | `h2` | `h3` | `h4` |
109+
| `h5` |`h6` | `header` | `hr` | `i` | `iframe`| `img` | `ins` | `kbd`| `li` | `main` |
110+
| `mark` | `nav` | `noscript`|`ol` | `p` | `pre` | `q` | `rp` | `rt` | `ruby` | `s` |
111+
| `samp` | `section` | `small` | `span`| `strike` | `strong`| `sub` | `sup` | `summary` | `svg`| `table`|
112+
| `tbody` | `td` | `template` | `tfoot` | `th` | `thead` |`time` | `tr` | `tt` | `u` | `ul` |
113+
| `var` | `video` | | | | | | | | | |
111114

112115

113116

@@ -640,6 +643,24 @@ This package renders table elements using the [`flutter_layout_grid`](https://pu
640643

641644
When rendering table elements, the package tries to calculate the best fit for each element and size its cell accordingly. `Rowspan`s and `colspan`s are considered in this process, so cells that span across multiple rows and columns are rendered as expected. Heights are determined intrinsically to maintain an optimal aspect ratio for the cell.
642645

646+
## Notes
647+
648+
1. If you'd like to use this widget inside of a `Row()`, make sure to set `shrinkWrap: true` and place your widget inside expanded:
649+
650+
```dart
651+
Widget row = Row(
652+
children: [
653+
Expanded(
654+
child: Html(
655+
shrinkWrap: true,
656+
//other params
657+
)
658+
),
659+
//whatever other widgets
660+
]
661+
);
662+
```
663+
643664
## Migration Guides
644665
- For Version 1.0 - [Guide](https://github.com/Sub6Resources/flutter_html/wiki/1.0.0-Migration-Guide)
645666

lib/html_parser.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class HtmlParser extends StatelessWidget {
6868
RenderContext(
6969
buildContext: context,
7070
parser: this,
71-
style: Style.fromTextStyle(Theme.of(context).textTheme.bodyText2),
7271
),
7372
cleanedTree,
7473
);
@@ -789,8 +788,7 @@ class StyledText extends StatelessWidget {
789788
@override
790789
Widget build(BuildContext context) {
791790
return SizedBox(
792-
width: (style.display == Display.BLOCK || style.display == Display.LIST_ITEM) && renderContext.parser.shrinkWrap != true
793-
? double.infinity : renderContext.parser.shrinkWrap == true ? MediaQuery.of(renderContext.buildContext).size.width : null,
791+
width: calculateWidth(style.display, renderContext),
794792
child: Text.rich(
795793
textSpan,
796794
style: style.generateTextStyle(),
@@ -800,4 +798,14 @@ class StyledText extends StatelessWidget {
800798
),
801799
);
802800
}
801+
802+
double calculateWidth(Display display, RenderContext context) {
803+
if ((display == Display.BLOCK || display == Display.LIST_ITEM) && renderContext.parser.shrinkWrap != true) {
804+
return double.infinity;
805+
} else if (renderContext.parser.shrinkWrap == true) {
806+
return MediaQuery.of(context.buildContext).size.width;
807+
} else {
808+
return null;
809+
}
810+
}
803811
}

lib/src/layout_element.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class DetailsContentElement extends LayoutElement {
285285
children: [firstChild] ?? [],
286286
),
287287
style: style,
288+
renderContext: context,
288289
) : Text("Details"),
289290
children: [
290291
StyledText(
@@ -293,6 +294,7 @@ class DetailsContentElement extends LayoutElement {
293294
children: getChildren(childrenList, context, elementList?.isNotEmpty == true && elementList?.first?.localName == "summary" ? firstChild : null)
294295
),
295296
style: style,
297+
renderContext: context,
296298
),
297299
]
298300
);

0 commit comments

Comments
 (0)