@@ -861,7 +861,7 @@ class HtmlParser extends StatelessWidget {
861861 if (tree.children.isEmpty) {
862862 // Handle case (4) from above.
863863 if ((tree.style.height ?? 0 ) == 0 ) {
864- tree.style.margin = EdgeInsets .zero;
864+ tree.style.margin = tree.style.margin ? . collapse () ?? Margins .zero;
865865 }
866866 return tree;
867867 }
@@ -877,72 +877,72 @@ class HtmlParser extends StatelessWidget {
877877 // Handle case (1) from above.
878878 // Top margins cannot collapse if the element has padding
879879 if ((tree.style.padding? .top ?? 0 ) == 0 ) {
880- final parentTop = tree.style.margin? .top ?? 0 ;
881- final firstChildTop = tree.children.first.style.margin? .top ?? 0 ;
880+ final parentTop = tree.style.margin? .top? .value ?? 0 ;
881+ final firstChildTop = tree.children.first.style.margin? .top? .value ?? 0 ;
882882 final newOuterMarginTop = max (parentTop, firstChildTop);
883883
884884 // Set the parent's margin
885885 if (tree.style.margin == null ) {
886- tree.style.margin = EdgeInsets .only (top: newOuterMarginTop);
886+ tree.style.margin = Margins .only (top: newOuterMarginTop);
887887 } else {
888- tree.style.margin = tree.style.margin! .copyWith (top: newOuterMarginTop);
888+ tree.style.margin = tree.style.margin! .copyWithEdge (top: newOuterMarginTop);
889889 }
890890
891891 // And remove the child's margin
892892 if (tree.children.first.style.margin == null ) {
893- tree.children.first.style.margin = EdgeInsets .zero;
893+ tree.children.first.style.margin = Margins .zero;
894894 } else {
895895 tree.children.first.style.margin =
896- tree.children.first.style.margin! .copyWith (top: 0 );
896+ tree.children.first.style.margin! .copyWithEdge (top: 0 );
897897 }
898898 }
899899
900900 // Handle case (3) from above.
901901 // Bottom margins cannot collapse if the element has padding
902902 if ((tree.style.padding? .bottom ?? 0 ) == 0 ) {
903- final parentBottom = tree.style.margin? .bottom ?? 0 ;
904- final lastChildBottom = tree.children.last.style.margin? .bottom ?? 0 ;
903+ final parentBottom = tree.style.margin? .bottom? .value ?? 0 ;
904+ final lastChildBottom = tree.children.last.style.margin? .bottom? .value ?? 0 ;
905905 final newOuterMarginBottom = max (parentBottom, lastChildBottom);
906906
907907 // Set the parent's margin
908908 if (tree.style.margin == null ) {
909- tree.style.margin = EdgeInsets .only (bottom: newOuterMarginBottom);
909+ tree.style.margin = Margins .only (bottom: newOuterMarginBottom);
910910 } else {
911911 tree.style.margin =
912- tree.style.margin! .copyWith (bottom: newOuterMarginBottom);
912+ tree.style.margin! .copyWithEdge (bottom: newOuterMarginBottom);
913913 }
914914
915915 // And remove the child's margin
916916 if (tree.children.last.style.margin == null ) {
917- tree.children.last.style.margin = EdgeInsets .zero;
917+ tree.children.last.style.margin = Margins .zero;
918918 } else {
919919 tree.children.last.style.margin =
920- tree.children.last.style.margin! .copyWith (bottom: 0 );
920+ tree.children.last.style.margin! .copyWithEdge (bottom: 0 );
921921 }
922922 }
923923
924924 // Handle case (2) from above.
925925 if (tree.children.length > 1 ) {
926926 for (int i = 1 ; i < tree.children.length; i++ ) {
927927 final previousSiblingBottom =
928- tree.children[i - 1 ].style.margin? .bottom ?? 0 ;
929- final thisTop = tree.children[i].style.margin? .top ?? 0 ;
928+ tree.children[i - 1 ].style.margin? .bottom? .value ?? 0 ;
929+ final thisTop = tree.children[i].style.margin? .top? .value ?? 0 ;
930930 final newInternalMargin = max (previousSiblingBottom, thisTop) / 2 ;
931931
932932 if (tree.children[i - 1 ].style.margin == null ) {
933933 tree.children[i - 1 ].style.margin =
934- EdgeInsets .only (bottom: newInternalMargin);
934+ Margins .only (bottom: newInternalMargin);
935935 } else {
936936 tree.children[i - 1 ].style.margin = tree.children[i - 1 ].style.margin!
937- .copyWith (bottom: newInternalMargin);
937+ .copyWithEdge (bottom: newInternalMargin);
938938 }
939939
940940 if (tree.children[i].style.margin == null ) {
941941 tree.children[i].style.margin =
942- EdgeInsets .only (top: newInternalMargin);
942+ Margins .only (top: newInternalMargin);
943943 } else {
944944 tree.children[i].style.margin =
945- tree.children[i].style.margin! .copyWith (top: newInternalMargin);
945+ tree.children[i].style.margin! .copyWithEdge (top: newInternalMargin);
946946 }
947947 }
948948 }
@@ -1049,15 +1049,15 @@ class ContainerSpan extends StatelessWidget {
10491049
10501050 @override
10511051 Widget build (BuildContext _) {
1052- return Container (
1052+ Widget container = Container (
10531053 decoration: BoxDecoration (
10541054 border: style.border,
10551055 color: style.backgroundColor,
10561056 ),
10571057 height: style.height,
10581058 width: style.width,
10591059 padding: style.padding? .nonNegative,
1060- margin: style.margin? .nonNegative,
1060+ margin: style.margin? .asInsets. nonNegative,
10611061 alignment: shrinkWrap ? null : style.alignment,
10621062 child: child ??
10631063 StyledText (
@@ -1069,6 +1069,12 @@ class ContainerSpan extends StatelessWidget {
10691069 renderContext: newContext,
10701070 ),
10711071 );
1072+
1073+ if (style.margin? .isAutoHorizontal ?? false ) {
1074+ return Align (alignment: style.margin! .alignment, child: container);
1075+ }
1076+
1077+ return container;
10721078 }
10731079}
10741080
0 commit comments