@@ -32,27 +32,35 @@ class TableLayoutElement extends LayoutElement {
32
32
@override
33
33
Widget toWidget (RenderContext context) {
34
34
final rows = < TableRowLayoutElement > [];
35
- List <TrackSize > columnSizes;
35
+ List <TrackSize > columnSizes = < TrackSize > [] ;
36
36
for (var child in children) {
37
37
if (child is TableStyleElement ) {
38
38
// Map <col> tags to predetermined column track sizes
39
- columnSizes = child.children.where ((c) => c.name == "col" ).map ((c) {
40
- final colWidth = c.attributes["width" ];
41
- if (colWidth != null && colWidth.endsWith ("%" )) {
42
- final percentageSize =
43
- double .tryParse (colWidth.substring (0 , colWidth.length - 1 ));
44
- return percentageSize != null
45
- ? FlexibleTrackSize (percentageSize * 0.01 )
46
- : FlexibleTrackSize (1 );
47
- } else if (colWidth != null ) {
48
- final fixedPxSize = double .tryParse (colWidth);
49
- return fixedPxSize != null
50
- ? FixedTrackSize (fixedPxSize)
51
- : FlexibleTrackSize (1 );
52
- } else {
53
- return FlexibleTrackSize (1 );
54
- }
55
- }).toList (growable: false );
39
+ columnSizes = child.children
40
+ .where ((c) => c.name == "col" )
41
+ .map ((c) {
42
+ final span =
43
+ int .parse (c.attributes["span" ] ?? "1" , onError: (_) => 1 );
44
+ final colWidth = c.attributes["width" ];
45
+ return List .generate (span, (index) {
46
+ if (colWidth != null && colWidth.endsWith ("%" )) {
47
+ final percentageSize = double .tryParse (
48
+ colWidth.substring (0 , colWidth.length - 1 ));
49
+ return percentageSize != null
50
+ ? FlexibleTrackSize (percentageSize * 0.01 )
51
+ : FlexibleTrackSize (1 );
52
+ } else if (colWidth != null ) {
53
+ final fixedPxSize = double .tryParse (colWidth);
54
+ return fixedPxSize != null
55
+ ? FixedTrackSize (fixedPxSize)
56
+ : FlexibleTrackSize (1 );
57
+ } else {
58
+ return FlexibleTrackSize (1 );
59
+ }
60
+ });
61
+ })
62
+ .expand ((element) => element)
63
+ .toList (growable: false );
56
64
} else if (child is TableSectionLayoutElement ) {
57
65
rows.addAll (child.children.whereType ());
58
66
} else if (child is TableRowLayoutElement ) {
@@ -71,6 +79,7 @@ class TableLayoutElement extends LayoutElement {
71
79
.fold (0 , (int value, child) => value + child.colspan))
72
80
.fold (0 , max);
73
81
82
+ // Place the cells in the rows/columns
74
83
final cells = < GridPlacement > [];
75
84
final columnRowOffset = List .generate (columnMax + 1 , (_) => 0 );
76
85
int rowi = 0 ;
@@ -113,8 +122,12 @@ class TableLayoutElement extends LayoutElement {
113
122
rowi++ ;
114
123
}
115
124
116
- final finalColumnSizes =
117
- columnSizes ?? List .generate (columnMax, (_) => FlexibleTrackSize (1 ));
125
+ // Create column tracks (insofar there were no colgroups that already defined them)
126
+ List <TrackSize > finalColumnSizes = (columnSizes ?? < TrackSize > []).take (
127
+ columnMax).toList ();
128
+ finalColumnSizes += List .generate (
129
+ max (0 , columnMax - finalColumnSizes.length),
130
+ (_) => FlexibleTrackSize (1 ));
118
131
return Container (
119
132
decoration: BoxDecoration (
120
133
color: style.backgroundColor,
0 commit comments