@@ -28,38 +28,46 @@ class TableLayoutElement extends LayoutElement {
28
28
29
29
@override
30
30
Widget toWidget (RenderContext context) {
31
-
32
- final colWidths = children.where ((c) => c.name == "colgroup" ).map ((group) {
33
- return group.children.where ((c) => c.name == "col" ).map ((c) {
34
- final widthStr = c.attributes["width" ] ?? "" ;
35
- if (widthStr.endsWith ("%" )) {
36
- final width = double .tryParse (widthStr.substring (0 , widthStr.length - 1 )) * 0.01 ;
37
- return FractionColumnWidth (width);
38
- } else {
39
- final width = double .tryParse (widthStr);
40
- return FixedColumnWidth (width);
41
- }
42
- });
43
- }).expand ((i) => i).toList ().asMap ();
31
+ final colWidths = children
32
+ .where ((c) => c.name == "colgroup" )
33
+ .map ((group) {
34
+ return group.children.where ((c) => c.name == "col" ).map ((c) {
35
+ final widthStr = c.attributes["width" ] ?? "" ;
36
+ if (widthStr.endsWith ("%" )) {
37
+ final width = double .tryParse (widthStr.substring (0 , widthStr.length - 1 )) * 0.01 ;
38
+ return FractionColumnWidth (width);
39
+ } else {
40
+ final width = double .tryParse (widthStr);
41
+ return FixedColumnWidth (width);
42
+ }
43
+ });
44
+ })
45
+ .expand ((i) => i)
46
+ .toList ()
47
+ .asMap ();
44
48
45
49
return Container (
46
50
decoration: BoxDecoration (
47
- color: style.backgroundColor
51
+ color: style.backgroundColor,
52
+ border: style.border,
48
53
),
54
+ width: style.width,
55
+ height: style.height,
49
56
child: Table (
50
57
columnWidths: colWidths,
51
- children: children.map ((c) {
52
- if (c is TableSectionLayoutElement ) {
53
- return c.toTableRows (context);
54
- }
55
- return null ;
56
- })
58
+ children: children
59
+ .map ((c) {
60
+ if (c is TableSectionLayoutElement ) {
61
+ return c.toTableRows (context);
62
+ }
63
+ return null ;
64
+ })
57
65
.where ((t) {
58
- return t != null ;
59
- })
60
- .toList ()
61
- .expand ((i) => i)
62
- .toList (),
66
+ return t != null ;
67
+ })
68
+ .toList ()
69
+ .expand ((i) => i)
70
+ .toList (),
63
71
));
64
72
}
65
73
}
@@ -101,21 +109,26 @@ class TableRowLayoutElement extends LayoutElement {
101
109
102
110
TableRow toTableRow (RenderContext context) {
103
111
return TableRow (
104
- decoration: BoxDecoration (
105
- border: style.border,
106
- ),
107
- children: children.map ((c) {
108
- if (c is StyledElement && c.name == 'td' || c.name == 'th' ) {
109
- return TableCell (
110
- child: Container (
111
- padding: c.style.padding,
112
- decoration: BoxDecoration (
113
- color: c.style.backgroundColor
114
- ),
115
- child: RichText (text: context.parser.parseTree (context, c))));
116
- }
117
- return null ;
118
- }).where ((c) => c != null ).toList ());
112
+ decoration: BoxDecoration (
113
+ border: style.border,
114
+ color: style.backgroundColor,
115
+ ),
116
+ children: children
117
+ .map ((c) {
118
+ if (c is StyledElement && c.name == 'td' || c.name == 'th' ) {
119
+ return TableCell (
120
+ child: Container (
121
+ padding: c.style.padding,
122
+ decoration: BoxDecoration (
123
+ color: c.style.backgroundColor,
124
+ border: c.style.border,
125
+ ),
126
+ child: RichText (text: context.parser.parseTree (context, c))));
127
+ }
128
+ return null ;
129
+ })
130
+ .where ((c) => c != null )
131
+ .toList ());
119
132
}
120
133
}
121
134
@@ -128,22 +141,24 @@ class TableStyleElement extends StyledElement {
128
141
}) : super (name: name, children: children, style: style, node: node);
129
142
}
130
143
131
- TableStyleElement parseTableDefinitionElement (
132
- dom.Element element, List <StyledElement > children) {
144
+ TableStyleElement parseTableDefinitionElement (dom.Element element, List <StyledElement > children) {
133
145
switch (element.localName) {
134
146
case "colgroup" :
135
147
case "col" :
136
148
return TableStyleElement (
137
- name: element.localName,
138
- children: children,
139
- node: element
149
+ name: element.localName,
150
+ children: children,
151
+ node: element,
140
152
);
141
153
default :
142
154
return TableStyleElement ();
143
155
}
144
156
}
157
+
145
158
LayoutElement parseLayoutElement (
146
- dom.Element element, List <StyledElement > children) {
159
+ dom.Element element,
160
+ List <StyledElement > children,
161
+ ) {
147
162
switch (element.localName) {
148
163
case "table" :
149
164
return TableLayoutElement (
@@ -161,11 +176,7 @@ LayoutElement parseLayoutElement(
161
176
);
162
177
break ;
163
178
case "tr" :
164
- return TableRowLayoutElement (
165
- name: element.localName,
166
- children: children,
167
- node: element
168
- );
179
+ return TableRowLayoutElement (name: element.localName, children: children, node: element);
169
180
break ;
170
181
default :
171
182
return TableLayoutElement (children: children);
0 commit comments