@@ -848,7 +848,7 @@ class HtmlParser extends StatelessWidget {
848848 if (tree.children.isEmpty) {
849849 // Handle case (4) from above.
850850 if ((tree.style.height ?? 0 ) == 0 ) {
851- tree.style.margin = EdgeInsets .zero ;
851+ tree.style.margin = Margins . all ( 0 ) ;
852852 }
853853 return tree;
854854 }
@@ -864,72 +864,73 @@ class HtmlParser extends StatelessWidget {
864864 // Handle case (1) from above.
865865 // Top margins cannot collapse if the element has padding
866866 if ((tree.style.padding? .top ?? 0 ) == 0 ) {
867- final parentTop = tree.style.margin? .top ?? 0 ;
868- final firstChildTop = tree.children.first.style.margin? .top ?? 0 ;
867+ final parentTop = tree.style.margin? .top? .value ?? 0 ;
868+ final firstChildTop = tree.children.first.style.margin? .top? .value ?? 0 ;
869869 final newOuterMarginTop = max (parentTop, firstChildTop);
870870
871871 // Set the parent's margin
872872 if (tree.style.margin == null ) {
873- tree.style.margin = EdgeInsets . only (top: newOuterMarginTop);
873+ tree.style.margin = Margins (top: Margin (value : newOuterMarginTop) );
874874 } else {
875- tree.style.margin = tree.style.margin! .copyWith (top: newOuterMarginTop);
875+ tree.style.margin = tree.style.margin! .copyWith (top: Margin (value : newOuterMarginTop) );
876876 }
877877
878878 // And remove the child's margin
879879 if (tree.children.first.style.margin == null ) {
880- tree.children.first.style.margin = EdgeInsets .zero ;
880+ tree.children.first.style.margin = Margins . all ( 0 ) ;
881881 } else {
882882 tree.children.first.style.margin =
883- tree.children.first.style.margin! .copyWith (top: 0 );
883+ tree.children.first.style.margin! .copyWith (top: Margin (value : 0 ) );
884884 }
885885 }
886886
887887 // Handle case (3) from above.
888888 // Bottom margins cannot collapse if the element has padding
889889 if ((tree.style.padding? .bottom ?? 0 ) == 0 ) {
890- final parentBottom = tree.style.margin? .bottom ?? 0 ;
891- final lastChildBottom = tree.children.last.style.margin? .bottom ?? 0 ;
890+ final parentBottom = tree.style.margin? .bottom? .value ?? 0 ;
891+ final lastChildBottom = tree.children.last.style.margin? .bottom? .value ?? 0 ;
892892 final newOuterMarginBottom = max (parentBottom, lastChildBottom);
893893
894894 // Set the parent's margin
895895 if (tree.style.margin == null ) {
896- tree.style.margin = EdgeInsets . only (bottom: newOuterMarginBottom);
896+ tree.style.margin = Margins (bottom: Margin (value : newOuterMarginBottom) );
897897 } else {
898- tree.style.margin =
899- tree.style.margin! .copyWith (bottom: newOuterMarginBottom);
898+ tree.style.margin = tree.style.margin! .copyWith (bottom: Margin (value: newOuterMarginBottom));
900899 }
901900
902901 // And remove the child's margin
903902 if (tree.children.last.style.margin == null ) {
904- tree.children.last.style.margin = EdgeInsets .zero ;
903+ tree.children.last.style.margin = Margins . all ( 0 ) ;
905904 } else {
906905 tree.children.last.style.margin =
907- tree.children.last.style.margin! .copyWith (bottom: 0 );
906+ tree.children.last.style.margin! .copyWith (bottom: Margin (
907+ value: 0
908+ ));
908909 }
909910 }
910911
911912 // Handle case (2) from above.
912913 if (tree.children.length > 1 ) {
913914 for (int i = 1 ; i < tree.children.length; i++ ) {
914915 final previousSiblingBottom =
915- tree.children[i - 1 ].style.margin? .bottom ?? 0 ;
916- final thisTop = tree.children[i].style.margin? .top ?? 0 ;
916+ tree.children[i - 1 ].style.margin? .bottom? .value ?? 0 ;
917+ final thisTop = tree.children[i].style.margin? .top? .value ?? 0 ;
917918 final newInternalMargin = max (previousSiblingBottom, thisTop) / 2 ;
918919
919920 if (tree.children[i - 1 ].style.margin == null ) {
920921 tree.children[i - 1 ].style.margin =
921- EdgeInsets . only (bottom: newInternalMargin);
922+ Margins (bottom: Margin (value : newInternalMargin) );
922923 } else {
923924 tree.children[i - 1 ].style.margin = tree.children[i - 1 ].style.margin!
924- .copyWith (bottom: newInternalMargin);
925+ .copyWith (bottom: Margin (value : newInternalMargin) );
925926 }
926927
927928 if (tree.children[i].style.margin == null ) {
928929 tree.children[i].style.margin =
929- EdgeInsets . only (top: newInternalMargin);
930+ Margins (top: Margin (value : newInternalMargin) );
930931 } else {
931932 tree.children[i].style.margin =
932- tree.children[i].style.margin! .copyWith (top: newInternalMargin);
933+ tree.children[i].style.margin! .copyWith (top: Margin (value : newInternalMargin) );
933934 }
934935 }
935936 }
@@ -1036,15 +1037,15 @@ class ContainerSpan extends StatelessWidget {
10361037
10371038 @override
10381039 Widget build (BuildContext _) {
1039- return Container (
1040+ Widget container = Container (
10401041 decoration: BoxDecoration (
10411042 border: style.border,
10421043 color: style.backgroundColor,
10431044 ),
10441045 height: style.height,
10451046 width: style.width,
10461047 padding: style.padding,
1047- margin: style.margin,
1048+ margin: style.margin? .asInsets ,
10481049 alignment: shrinkWrap ? null : style.alignment,
10491050 child: child ??
10501051 StyledText (
@@ -1056,6 +1057,13 @@ class ContainerSpan extends StatelessWidget {
10561057 renderContext: newContext,
10571058 ),
10581059 );
1060+ if (style.margin? .isAutoHorizontal ?? false ) {
1061+ return Row (
1062+ mainAxisAlignment: style.margin? .alignment ?? MainAxisAlignment .start,
1063+ children: [container],
1064+ );
1065+ }
1066+ return container;
10591067 }
10601068}
10611069
0 commit comments