@@ -848,7 +848,7 @@ class HtmlParser extends StatelessWidget {
848
848
if (tree.children.isEmpty) {
849
849
// Handle case (4) from above.
850
850
if ((tree.style.height ?? 0 ) == 0 ) {
851
- tree.style.margin = EdgeInsets .zero ;
851
+ tree.style.margin = Margins . all ( 0 ) ;
852
852
}
853
853
return tree;
854
854
}
@@ -864,72 +864,73 @@ class HtmlParser extends StatelessWidget {
864
864
// Handle case (1) from above.
865
865
// Top margins cannot collapse if the element has padding
866
866
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 ;
869
869
final newOuterMarginTop = max (parentTop, firstChildTop);
870
870
871
871
// Set the parent's margin
872
872
if (tree.style.margin == null ) {
873
- tree.style.margin = EdgeInsets . only (top: newOuterMarginTop);
873
+ tree.style.margin = Margins (top: Margin (value : newOuterMarginTop) );
874
874
} else {
875
- tree.style.margin = tree.style.margin! .copyWith (top: newOuterMarginTop);
875
+ tree.style.margin = tree.style.margin! .copyWith (top: Margin (value : newOuterMarginTop) );
876
876
}
877
877
878
878
// And remove the child's margin
879
879
if (tree.children.first.style.margin == null ) {
880
- tree.children.first.style.margin = EdgeInsets .zero ;
880
+ tree.children.first.style.margin = Margins . all ( 0 ) ;
881
881
} else {
882
882
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 ) );
884
884
}
885
885
}
886
886
887
887
// Handle case (3) from above.
888
888
// Bottom margins cannot collapse if the element has padding
889
889
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 ;
892
892
final newOuterMarginBottom = max (parentBottom, lastChildBottom);
893
893
894
894
// Set the parent's margin
895
895
if (tree.style.margin == null ) {
896
- tree.style.margin = EdgeInsets . only (bottom: newOuterMarginBottom);
896
+ tree.style.margin = Margins (bottom: Margin (value : newOuterMarginBottom) );
897
897
} else {
898
- tree.style.margin =
899
- tree.style.margin! .copyWith (bottom: newOuterMarginBottom);
898
+ tree.style.margin = tree.style.margin! .copyWith (bottom: Margin (value: newOuterMarginBottom));
900
899
}
901
900
902
901
// And remove the child's margin
903
902
if (tree.children.last.style.margin == null ) {
904
- tree.children.last.style.margin = EdgeInsets .zero ;
903
+ tree.children.last.style.margin = Margins . all ( 0 ) ;
905
904
} else {
906
905
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
+ ));
908
909
}
909
910
}
910
911
911
912
// Handle case (2) from above.
912
913
if (tree.children.length > 1 ) {
913
914
for (int i = 1 ; i < tree.children.length; i++ ) {
914
915
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 ;
917
918
final newInternalMargin = max (previousSiblingBottom, thisTop) / 2 ;
918
919
919
920
if (tree.children[i - 1 ].style.margin == null ) {
920
921
tree.children[i - 1 ].style.margin =
921
- EdgeInsets . only (bottom: newInternalMargin);
922
+ Margins (bottom: Margin (value : newInternalMargin) );
922
923
} else {
923
924
tree.children[i - 1 ].style.margin = tree.children[i - 1 ].style.margin!
924
- .copyWith (bottom: newInternalMargin);
925
+ .copyWith (bottom: Margin (value : newInternalMargin) );
925
926
}
926
927
927
928
if (tree.children[i].style.margin == null ) {
928
929
tree.children[i].style.margin =
929
- EdgeInsets . only (top: newInternalMargin);
930
+ Margins (top: Margin (value : newInternalMargin) );
930
931
} else {
931
932
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) );
933
934
}
934
935
}
935
936
}
@@ -1036,15 +1037,15 @@ class ContainerSpan extends StatelessWidget {
1036
1037
1037
1038
@override
1038
1039
Widget build (BuildContext _) {
1039
- return Container (
1040
+ Widget container = Container (
1040
1041
decoration: BoxDecoration (
1041
1042
border: style.border,
1042
1043
color: style.backgroundColor,
1043
1044
),
1044
1045
height: style.height,
1045
1046
width: style.width,
1046
1047
padding: style.padding,
1047
- margin: style.margin,
1048
+ margin: style.margin? .asInsets ,
1048
1049
alignment: shrinkWrap ? null : style.alignment,
1049
1050
child: child ??
1050
1051
StyledText (
@@ -1056,6 +1057,13 @@ class ContainerSpan extends StatelessWidget {
1056
1057
renderContext: newContext,
1057
1058
),
1058
1059
);
1060
+ if (style.margin? .isAutoHorizontal ?? false ) {
1061
+ return Row (
1062
+ mainAxisAlignment: style.margin? .alignment ?? MainAxisAlignment .start,
1063
+ children: [container],
1064
+ );
1065
+ }
1066
+ return container;
1059
1067
}
1060
1068
}
1061
1069
0 commit comments