@@ -18,7 +18,12 @@ abstract class LayoutElement extends StyledElement {
18
18
required List <StyledElement > children,
19
19
String ? elementId,
20
20
dom.Element ? node,
21
- }) : super (name: name, children: children, style: Style (), node: node, elementId: elementId ?? "[[No ID]]" );
21
+ }) : super (
22
+ name: name,
23
+ children: children,
24
+ style: Style (),
25
+ node: node,
26
+ elementId: elementId ?? "[[No ID]]" );
22
27
23
28
Widget ? toWidget (RenderContext context);
24
29
}
@@ -34,16 +39,16 @@ class TableLayoutElement extends LayoutElement {
34
39
Widget toWidget (RenderContext context) {
35
40
return Container (
36
41
key: AnchorKey .of (context.parser.key, this ),
42
+ margin: style.margin? .asInsets.nonNegative ?? EdgeInsets .zero,
37
43
padding: style.padding? .nonNegative,
38
- margin: style.margin? .nonNegative,
39
- alignment: style.alignment,
40
44
decoration: BoxDecoration (
41
45
color: style.backgroundColor,
42
46
border: style.border,
43
47
),
44
48
width: style.width,
45
49
height: style.height,
46
- child: LayoutBuilder (builder: (_, constraints) => _layoutCells (context, constraints)),
50
+ child: LayoutBuilder (
51
+ builder: (_, constraints) => _layoutCells (context, constraints)),
47
52
);
48
53
}
49
54
@@ -89,18 +94,23 @@ class TableLayoutElement extends LayoutElement {
89
94
}
90
95
91
96
// All table rows have a height intrinsic to their (spanned) contents
92
- final rowSizes = List .generate (rows.length, (_) => IntrinsicContentTrackSize ());
97
+ final rowSizes =
98
+ List .generate (rows.length, (_) => IntrinsicContentTrackSize ());
93
99
94
100
// Calculate column bounds
95
101
int columnMax = 0 ;
96
102
List <int > rowSpanOffsets = [];
97
103
for (final row in rows) {
98
- final cols = row.children.whereType <TableCellElement >().fold (0 , (int value, child) => value + child.colspan) +
104
+ final cols = row.children
105
+ .whereType <TableCellElement >()
106
+ .fold (0 , (int value, child) => value + child.colspan) +
99
107
rowSpanOffsets.fold <int >(0 , (int offset, child) => child);
100
108
columnMax = max (cols, columnMax);
101
109
rowSpanOffsets = [
102
110
...rowSpanOffsets.map ((value) => value - 1 ).where ((value) => value > 0 ),
103
- ...row.children.whereType <TableCellElement >().map ((cell) => cell.rowspan - 1 ),
111
+ ...row.children
112
+ .whereType <TableCellElement >()
113
+ .map ((cell) => cell.rowspan - 1 ),
104
114
];
105
115
}
106
116
@@ -112,19 +122,21 @@ class TableLayoutElement extends LayoutElement {
112
122
for (var row in rows) {
113
123
int columni = 0 ;
114
124
for (var child in row.children) {
115
- if (columni > columnMax - 1 ) {
125
+ if (columni > columnMax - 1 ) {
116
126
break ;
117
127
}
118
128
if (child is TableCellElement ) {
119
129
while (columnRowOffset[columni] > 0 ) {
120
130
columnRowOffset[columni] = columnRowOffset[columni] - 1 ;
121
- columni += columnColspanOffset[columni].clamp (1 , columnMax - columni - 1 );
131
+ columni +=
132
+ columnColspanOffset[columni].clamp (1 , columnMax - columni - 1 );
122
133
}
123
134
cells.add (GridPlacement (
124
135
child: Container (
125
136
width: child.style.width ?? double .infinity,
126
137
height: child.style.height,
127
- padding: child.style.padding? .nonNegative ?? row.style.padding? .nonNegative,
138
+ padding: child.style.padding? .nonNegative ??
139
+ row.style.padding? .nonNegative,
128
140
decoration: BoxDecoration (
129
141
color: child.style.backgroundColor ?? row.style.backgroundColor,
130
142
border: child.style.border ?? row.style.border,
@@ -217,7 +229,13 @@ class TableCellElement extends StyledElement {
217
229
required List <StyledElement > children,
218
230
required Style style,
219
231
required dom.Element node,
220
- }) : super (name: name, elementId: elementId, elementClasses: elementClasses, children: children, style: style, node: node) {
232
+ }) : super (
233
+ name: name,
234
+ elementId: elementId,
235
+ elementClasses: elementClasses,
236
+ children: children,
237
+ style: style,
238
+ node: node) {
221
239
colspan = _parseSpan (this , "colspan" );
222
240
rowspan = _parseSpan (this , "rowspan" );
223
241
}
@@ -292,42 +310,55 @@ class DetailsContentElement extends LayoutElement {
292
310
293
311
@override
294
312
Widget toWidget (RenderContext context) {
295
- List <InlineSpan >? childrenList = children.map ((tree) => context.parser.parseTree (context, tree)).toList ();
313
+ List <InlineSpan >? childrenList = children
314
+ .map ((tree) => context.parser.parseTree (context, tree))
315
+ .toList ();
296
316
List <InlineSpan > toRemove = [];
297
317
for (InlineSpan child in childrenList) {
298
- if (child is TextSpan && child.text != null && child.text! .trim ().isEmpty) {
318
+ if (child is TextSpan &&
319
+ child.text != null &&
320
+ child.text! .trim ().isEmpty) {
299
321
toRemove.add (child);
300
322
}
301
323
}
302
324
for (InlineSpan child in toRemove) {
303
325
childrenList.remove (child);
304
326
}
305
- InlineSpan ? firstChild = childrenList.isNotEmpty == true ? childrenList.first : null ;
327
+ InlineSpan ? firstChild =
328
+ childrenList.isNotEmpty == true ? childrenList.first : null ;
306
329
return ExpansionTile (
307
330
key: AnchorKey .of (context.parser.key, this ),
308
331
expandedAlignment: Alignment .centerLeft,
309
- title: elementList.isNotEmpty == true && elementList.first.localName == "summary" ? StyledText (
310
- textSpan: TextSpan (
311
- style: style.generateTextStyle (),
312
- children: firstChild == null ? [] : [firstChild],
313
- ),
314
- style: style,
315
- renderContext: context,
316
- ) : Text ("Details" ),
332
+ title: elementList.isNotEmpty == true &&
333
+ elementList.first.localName == "summary"
334
+ ? StyledText (
335
+ textSpan: TextSpan (
336
+ style: style.generateTextStyle (),
337
+ children: firstChild == null ? [] : [firstChild],
338
+ ),
339
+ style: style,
340
+ renderContext: context,
341
+ )
342
+ : Text ("Details" ),
317
343
children: [
318
344
StyledText (
319
345
textSpan: TextSpan (
320
- style: style.generateTextStyle (),
321
- children: getChildren (childrenList, context, elementList.isNotEmpty == true && elementList.first.localName == "summary" ? firstChild : null )
322
- ),
346
+ style: style.generateTextStyle (),
347
+ children: getChildren (
348
+ childrenList,
349
+ context,
350
+ elementList.isNotEmpty == true &&
351
+ elementList.first.localName == "summary"
352
+ ? firstChild
353
+ : null )),
323
354
style: style,
324
355
renderContext: context,
325
356
),
326
- ]
327
- );
357
+ ]);
328
358
}
329
359
330
- List <InlineSpan > getChildren (List <InlineSpan > children, RenderContext context, InlineSpan ? firstChild) {
360
+ List <InlineSpan > getChildren (List <InlineSpan > children, RenderContext context,
361
+ InlineSpan ? firstChild) {
331
362
if (firstChild != null ) children.removeAt (0 );
332
363
return children;
333
364
}
@@ -341,8 +372,8 @@ class EmptyLayoutElement extends LayoutElement {
341
372
}
342
373
343
374
LayoutElement parseLayoutElement (
344
- dom.Element element,
345
- List <StyledElement > children,
375
+ dom.Element element,
376
+ List <StyledElement > children,
346
377
) {
347
378
switch (element.localName) {
348
379
case "details" :
@@ -353,8 +384,7 @@ LayoutElement parseLayoutElement(
353
384
node: element,
354
385
name: element.localName! ,
355
386
children: children,
356
- elementList: element.children
357
- );
387
+ elementList: element.children);
358
388
case "table" :
359
389
return TableLayoutElement (
360
390
name: element.localName! ,
@@ -376,9 +406,6 @@ LayoutElement parseLayoutElement(
376
406
);
377
407
default :
378
408
return TableLayoutElement (
379
- children: children,
380
- name: "[[No Name]]" ,
381
- node: element
382
- );
409
+ children: children, name: "[[No Name]]" , node: element);
383
410
}
384
411
}
0 commit comments