@@ -5,6 +5,7 @@ import 'package:flutter_html/html_parser.dart';
5
5
import 'package:flutter_html/src/anchor.dart' ;
6
6
import 'package:flutter_html/src/html_elements.dart' ;
7
7
import 'package:flutter_html/src/styled_element.dart' ;
8
+ import 'package:flutter_html/src/utils.dart' ;
8
9
import 'package:flutter_html/style.dart' ;
9
10
import 'package:flutter_layout_grid/flutter_layout_grid.dart' ;
10
11
import 'package:html/dom.dart' as dom;
@@ -33,8 +34,9 @@ class TableLayoutElement extends LayoutElement {
33
34
Widget toWidget (RenderContext context) {
34
35
return Container (
35
36
key: AnchorKey .of (context.parser.key, this ),
36
- margin: style.margin,
37
- padding: style.padding,
37
+ padding: style.padding? .nonNegative,
38
+ margin: style.margin? .nonNegative,
39
+ alignment: style.alignment,
38
40
decoration: BoxDecoration (
39
41
color: style.backgroundColor,
40
42
border: style.border,
@@ -87,35 +89,42 @@ class TableLayoutElement extends LayoutElement {
87
89
}
88
90
89
91
// All table rows have a height intrinsic to their (spanned) contents
90
- final rowSizes =
91
- List .generate (rows.length, (_) => IntrinsicContentTrackSize ());
92
+ final rowSizes = List .generate (rows.length, (_) => IntrinsicContentTrackSize ());
92
93
93
94
// Calculate column bounds
94
- int columnMax = rows
95
- .map ((row) => row.children
96
- .whereType <TableCellElement >()
97
- .fold (0 , (int value, child) => value + child.colspan))
98
- .fold (0 , max);
95
+ int columnMax = 0 ;
96
+ List <int > rowSpanOffsets = [];
97
+ for (final row in rows) {
98
+ final cols = row.children.whereType <TableCellElement >().fold (0 , (int value, child) => value + child.colspan) +
99
+ rowSpanOffsets.fold <int >(0 , (int offset, child) => child);
100
+ columnMax = max (cols, columnMax);
101
+ rowSpanOffsets = [
102
+ ...rowSpanOffsets.map ((value) => value - 1 ).where ((value) => value > 0 ),
103
+ ...row.children.whereType <TableCellElement >().map ((cell) => cell.rowspan - 1 ),
104
+ ];
105
+ }
99
106
100
107
// Place the cells in the rows/columns
101
108
final cells = < GridPlacement > [];
102
109
final columnRowOffset = List .generate (columnMax, (_) => 0 );
110
+ final columnColspanOffset = List .generate (columnMax, (_) => 0 );
103
111
int rowi = 0 ;
104
112
for (var row in rows) {
105
113
int columni = 0 ;
106
114
for (var child in row.children) {
107
115
if (columni > columnMax - 1 ) {
108
116
break ;
109
117
}
110
- while (columnRowOffset[columni] > 0 ) {
111
- columnRowOffset[columni] = columnRowOffset[columni] - 1 ;
112
- columni++ ;
113
- }
114
118
if (child is TableCellElement ) {
119
+ while (columnRowOffset[columni] > 0 ) {
120
+ columnRowOffset[columni] = columnRowOffset[columni] - 1 ;
121
+ columni += columnColspanOffset[columni].clamp (1 , columnMax - columni - 1 );
122
+ }
115
123
cells.add (GridPlacement (
116
124
child: Container (
117
- width: double .infinity,
118
- padding: child.style.padding ?? row.style.padding,
125
+ width: child.style.width ?? double .infinity,
126
+ height: child.style.height,
127
+ padding: child.style.padding? .nonNegative ?? row.style.padding? .nonNegative,
119
128
decoration: BoxDecoration (
120
129
color: child.style.backgroundColor ?? row.style.backgroundColor,
121
130
border: child.style.border ?? row.style.border,
@@ -139,6 +148,7 @@ class TableLayoutElement extends LayoutElement {
139
148
rowSpan: min (child.rowspan, rows.length - rowi),
140
149
));
141
150
columnRowOffset[columni] = child.rowspan - 1 ;
151
+ columnColspanOffset[columni] = child.colspan;
142
152
columni += child.colspan;
143
153
}
144
154
}
@@ -155,6 +165,11 @@ class TableLayoutElement extends LayoutElement {
155
165
max (0 , columnMax - finalColumnSizes.length),
156
166
(_) => IntrinsicContentTrackSize ());
157
167
168
+ if (finalColumnSizes.isEmpty || rowSizes.isEmpty) {
169
+ // No actual cells to show
170
+ return SizedBox ();
171
+ }
172
+
158
173
return LayoutGrid (
159
174
gridFit: GridFit .loose,
160
175
columnSizes: finalColumnSizes,
0 commit comments