File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -518,6 +518,8 @@ class RenderTable extends RenderBox {
518
518
/// the table, unlike decorations for individual cells, which might not fill
519
519
/// either.
520
520
List <Decoration > get rowDecorations => List <Decoration >.unmodifiable (_rowDecorations ?? const < Decoration > []);
521
+ // _rowDecorations and _rowDecorationPainters need to be in sync. They have to
522
+ // either both be null or have same length.
521
523
List <Decoration > _rowDecorations;
522
524
List <BoxPainter > _rowDecorationPainters;
523
525
set rowDecorations (List <Decoration > value) {
@@ -703,7 +705,7 @@ class RenderTable extends RenderBox {
703
705
if (_rowDecorationPainters != null ) {
704
706
for (BoxPainter painter in _rowDecorationPainters)
705
707
painter? .dispose ();
706
- _rowDecorationPainters = null ;
708
+ _rowDecorationPainters = List < BoxPainter >(_rowDecorations.length) ;
707
709
}
708
710
for (RenderBox child in _children)
709
711
child? .detach ();
@@ -1137,6 +1139,7 @@ class RenderTable extends RenderBox {
1137
1139
}
1138
1140
assert (_rowTops.length == rows + 1 );
1139
1141
if (_rowDecorations != null ) {
1142
+ assert (_rowDecorations.length == _rowDecorationPainters.length);
1140
1143
final Canvas canvas = context.canvas;
1141
1144
for (int y = 0 ; y < rows; y += 1 ) {
1142
1145
if (_rowDecorations.length <= y)
Original file line number Diff line number Diff line change 5
5
import 'package:flutter_test/flutter_test.dart' ;
6
6
import 'package:flutter/rendering.dart' ;
7
7
import 'package:flutter/widgets.dart' ;
8
+ import 'package:flutter/material.dart' ;
8
9
9
10
class TestStatefulWidget extends StatefulWidget {
10
11
const TestStatefulWidget ({ Key key }) : super (key: key);
@@ -67,6 +68,41 @@ void main() {
67
68
await run (TextDirection .rtl);
68
69
});
69
70
71
+ testWidgets ('Table widget can be detached and re-attached' , (WidgetTester tester) async {
72
+ final Widget table = Table (
73
+ key: GlobalKey (),
74
+ children: const < TableRow > [
75
+ TableRow (
76
+ decoration: BoxDecoration (
77
+ color: Colors .yellow
78
+ ),
79
+ children: < Widget > [Placeholder ()],
80
+ ),
81
+ ],
82
+ );
83
+ await tester.pumpWidget (
84
+ Directionality (
85
+ textDirection: TextDirection .ltr,
86
+ child: Center (
87
+ child: table,
88
+ ),
89
+ ),
90
+ );
91
+ // Move table to a different location to simulate detaching and re-attaching effect.
92
+ await tester.pumpWidget (
93
+ Directionality (
94
+ textDirection: TextDirection .ltr,
95
+ child: Center (
96
+ child: Center (
97
+ child: table
98
+ ),
99
+ ),
100
+ ),
101
+ );
102
+
103
+ expect (tester.takeException (), isNull);
104
+ });
105
+
70
106
testWidgets ('Table widget - column offset (LTR)' , (WidgetTester tester) async {
71
107
await tester.pumpWidget (
72
108
Directionality (
You can’t perform that action at this time.
0 commit comments