@@ -25,17 +25,52 @@ import '../../widgets.dart';
25
25
/// A horizontal group of cells in a [Table] .
26
26
@immutable
27
27
class TableRow {
28
- const TableRow ({
28
+ TableRow ({
29
29
required this .children,
30
30
this .repeat = false ,
31
31
this .verticalAlignment,
32
32
this .decoration,
33
33
this .columnSpans,
34
- });
34
+ }) {
35
+ if (columnSpans == null ) {
36
+ spanFilledChildren = children;
37
+ return ;
38
+ }
39
+ var n = 0 ;
40
+ // TODO: handle intrinsic layout
41
+ spanFilledChildren = < Widget > [];
42
+ for (final child in children) {
43
+ // Columns, which are currently spanned.
44
+ final columnSpan = columnSpans! [n] ?? 1 ;
45
+ spanFilledChildren.add (child);
46
+ if (columnSpan > 1 ) {
47
+ spanFilledChildren
48
+ .addAll (Iterable .generate (columnSpan - 1 , (index) => Container ()));
49
+ }
50
+ n += columnSpan;
51
+ }
52
+ // final indices = Iterable.generate(columnSpan, (span) => n + span);
53
+ //
54
+ // final columnLayout =
55
+ // indices.fold(ColumnLayout(null, null), (prev, curIndex) {
56
+ // final curColumnWidth = _getTableColumnWidth(curIndex);
57
+ // final currentColumnLayout =
58
+ // curColumnWidth.layout(child, context, constraints);
59
+ // return ColumnLayout(
60
+ // (prev.width == null && currentColumnLayout.width == null)
61
+ // ? null
62
+ // : (prev.width ?? 0) + (currentColumnLayout.width ?? 0),
63
+ // (prev.flex == null && currentColumnLayout.flex == null)
64
+ // ? null
65
+ // : (prev.flex ?? 0) + (currentColumnLayout.flex ?? 0));
66
+ // });
67
+ }
35
68
36
69
/// The widgets that comprise the cells in this row.
37
70
final List <Widget > children;
38
71
72
+ late final List <Widget > spanFilledChildren;
73
+
39
74
/// Repeat this row on all pages
40
75
final bool repeat;
41
76
@@ -337,48 +372,22 @@ class Table extends Widget with SpanningWidget {
337
372
_context.firstLine = _context.lastLine;
338
373
}
339
374
340
- TableColumnWidth _getTableColumnWidth (int n) {
341
- final colWidths = columnWidths;
342
- if (colWidths == null ) {
343
- return defaultColumnWidth;
344
- }
345
- final curColWidth = colWidths[n];
346
- if (curColWidth == null ) {
347
- return defaultColumnWidth;
348
- }
349
- return curColWidth;
350
- }
351
-
352
375
@override
353
376
void layout (Context context, BoxConstraints constraints,
354
377
{bool parentUsesSize = false }) {
355
378
// Compute required width for all row/columns width flex
356
379
final flex = < double ? > [];
380
+ final widths = < double ? > [];
357
381
_heights.clear ();
358
382
var index = 0 ;
359
383
360
384
for (final row in children) {
361
- final widths = < double ? > [];
362
385
var n = 0 ;
363
- for (final child in row.children) {
364
- final columnSpans = row.columnSpans;
365
- // Columns, which are currently spanned.
366
- final columnSpan = columnSpans? [n] ?? 1 ;
367
- final indices = Iterable .generate (columnSpan, (span) => n + span);
368
-
369
- final columnLayout =
370
- indices.fold (ColumnLayout (null , null ), (prev, curIndex) {
371
- final curColumnWidth = _getTableColumnWidth (curIndex);
372
- final currentColumnLayout =
373
- curColumnWidth.layout (child, context, constraints);
374
- return ColumnLayout (
375
- (prev.width == null && currentColumnLayout.width == null )
376
- ? null
377
- : (prev.width ?? 0 ) + (currentColumnLayout.width ?? 0 ),
378
- (prev.flex == null && currentColumnLayout.flex == null )
379
- ? null
380
- : (prev.flex ?? 0 ) + (currentColumnLayout.flex ?? 0 ));
381
- });
386
+ for (final child in row.spanFilledChildren) {
387
+ final columnWidth = columnWidths != null && columnWidths! [n] != null
388
+ ? columnWidths! [n]!
389
+ : defaultColumnWidth;
390
+ final columnLayout = columnWidth.layout (child, context, constraints);
382
391
if (flex.length < n + 1 ) {
383
392
flex.add (columnLayout.flex);
384
393
widths.add (columnLayout.width);
@@ -388,7 +397,7 @@ class Table extends Widget with SpanningWidget {
388
397
}
389
398
widths[n] = math.max (widths[n]! , columnLayout.width! );
390
399
}
391
- n += columnSpan ?? 1 ;
400
+ n++ ;
392
401
}
393
402
}
394
403
@@ -439,7 +448,7 @@ class Table extends Widget with SpanningWidget {
439
448
var x = 0.0 ;
440
449
441
450
var lineHeight = 0.0 ;
442
- for (final child in row.children ) {
451
+ for (final child in row.spanFilledChildren ) {
443
452
final childConstraints = BoxConstraints .tightFor (width: widths[n]);
444
453
child.layout (context, childConstraints);
445
454
assert (child.box != null );
@@ -456,7 +465,7 @@ class Table extends Widget with SpanningWidget {
456
465
// Compute the layout again to give the full height to all cells
457
466
n = 0 ;
458
467
x = 0 ;
459
- for (final child in row.children ) {
468
+ for (final child in row.spanFilledChildren ) {
460
469
final childConstraints =
461
470
BoxConstraints .tightFor (width: widths[n], height: lineHeight);
462
471
child.layout (context, childConstraints);
@@ -487,7 +496,7 @@ class Table extends Widget with SpanningWidget {
487
496
488
497
final align = row.verticalAlignment ?? defaultVerticalAlignment;
489
498
490
- for (final child in row.children ) {
499
+ for (final child in row.spanFilledChildren ) {
491
500
double ? childY;
492
501
493
502
switch (align) {
@@ -548,7 +557,7 @@ class Table extends Widget with SpanningWidget {
548
557
if (row.decoration != null ) {
549
558
var y = double .infinity;
550
559
var h = 0.0 ;
551
- for (final child in row.children ) {
560
+ for (final child in row.spanFilledChildren ) {
552
561
y = math.min (y, child.box! .y);
553
562
h = math.max (h, child.box! .height);
554
563
}
@@ -559,7 +568,7 @@ class Table extends Widget with SpanningWidget {
559
568
);
560
569
}
561
570
562
- for (final child in row.children ) {
571
+ for (final child in row.spanFilledChildren ) {
563
572
context.canvas
564
573
..saveContext ()
565
574
..drawRect (
@@ -582,7 +591,7 @@ class Table extends Widget with SpanningWidget {
582
591
if (row.decoration != null ) {
583
592
var y = double .infinity;
584
593
var h = 0.0 ;
585
- for (final child in row.children ) {
594
+ for (final child in row.spanFilledChildren ) {
586
595
y = math.min (y, child.box! .y);
587
596
h = math.max (h, child.box! .height);
588
597
}
0 commit comments