flutter_html_css_percent_size 0.3.0
flutter_html_css_percent_size: ^0.3.0 copied to clipboard
A flutter_html extension that renders percentage width, height, padding and margin, which flutter_html 3.0.0 parses as zero.
0.3.0 #
- Renamed from
flutter_html_css_percent_size_extensionon pub.flutter-io.cn. The old package stays published and is marked discontinued with this one as its replacement. Class names are unchanged.
0.2.0 #
- Percentage padding and margin.
flutter_html3.0.0 loses them two ways: thepaddingandmarginshorthands run aremoveWherethat strips everyPercentageTerm, sopadding: 5%sets nothing andpadding: 5% 10pxturns into 10px on all four sides; the sixteen longhands go through the sameexpressionToLengthOrPercentbranch that zeroeswidth: 50%, sopadding-left: 5%is a padding of zero. No error, no warning. Re-measured: a<div style="padding: 5%">is 20 px high wherepadding: 40pxgives 100. - Same mechanism as width: at the
buildingstep we resolve every side against the containing block's width (all four sides, as CSS says) and write logical pixels intoStyle.paddingandStyle.margin.padding: 5%in a 784-wide block now renders bit-for-bit likepadding: 39.2px: paragraph at 47.2, box 98.4 high. Shorthands, longhands and the-inline/-blocklogical forms, 22 property names in all, listed inkCssPercentEdgeProperties. - A mixed shorthand is expanded by us in full, because
flutter_htmlexpands what is left after the strip:padding: 5% 10px 20pxused to render 10 above and below and 20 left and right, and now renders 39.2, 10, 20, 10.px,em,rem, bare numbers andautoride along; acalc()term in such a shorthand stays withflutter_html. - Negative margins work (
margin-left: -5%pulls the paragraph out by 39.2), a negative padding is written as zero, andmargin: 5% autostill centres awidth: 50%block. - What it doesn't do: collapse.
flutter_htmlcollapses margins at thepreProcessingstep, when a percentage still reads as zero, and we write the pixels afterwards. Two adjacent<div style="margin: 5%">sit 100 apart where the same margin in pixels gives 61. Documented in the README. - Companions, measured:
padding: 5%; max-width: 100pxgives a padding of 5 withCssSizeConstraintsHtmlExtensionfirst (the basis is the clamped 100) and 39.2 with it second, and unlike thewidthcase the clamp survives either order. The pinned order stays.CssInteractionHtmlExtension'sMouseRegioncovers the padding and the margin in either order, andCssBorderHtmlExtensionputs the border outside the padding in either order. No new order rule. resolvePercentages: falsenow zeroes every percentage side, and still writes the pixel sides of a mixed shorthand, sopadding: 5% 10pxkeeps its 10 left and right instead offlutter_html's 10 on all four.CssPercentSizesgainspaddingandmargin(CssPercentEdges, eightCssEdgeLength?sides) andhasPercent. Nothing existing changed shape.- Dev dependency on
flutter_html_css_object_fitmoved from git to pub.flutter-io.cn now that 0.1.0 is hosted. 49 new tests, 96 in all.
0.1.0 #
- Initial release.
flutter_html3.0.0 parseswidthandheightbut has no branch for a percentage value, sowidth: 50%comes out as zero pixels. A<div>collapses, an<img style="width: 50%">isSize(0, 0)and disappears, and there is no error and no warning. This extension resolves the percentage against the incoming constraints at thebuildingstep and writes logical pixels intoStyle.widthandStyle.height. In a containing block of 784 that same<div>is 392 wide, and that same image isSize(392, 196)with its aspect ratio intact, because the pixel width reachesImage.width. - Whatever extension or built-in would have rendered the element still renders
it. We only change the
Styleon the way through. - Can't resolve a percentage? We drop it, so the used value is
auto. That is what CSS does with an invalid declaration, and it still beats the zero. resolvePercentages: falsefor anHtmlunder anIntrinsicHeightor anIntrinsicWidth. Resolving needs aLayoutBuilder, aLayoutBuildercan't do dry layout, and the tree throws otherwise.