Unverified Commit ad507723 authored by chunhtai's avatar chunhtai Committed by GitHub

fix Applying decoration for a table row widget will cause render exception (#34285)

parent c40c687b
......@@ -518,6 +518,8 @@ class RenderTable extends RenderBox {
/// the table, unlike decorations for individual cells, which might not fill
/// either.
List<Decoration> get rowDecorations => List<Decoration>.unmodifiable(_rowDecorations ?? const <Decoration>[]);
// _rowDecorations and _rowDecorationPainters need to be in sync. They have to
// either both be null or have same length.
List<Decoration> _rowDecorations;
List<BoxPainter> _rowDecorationPainters;
set rowDecorations(List<Decoration> value) {
......@@ -703,7 +705,7 @@ class RenderTable extends RenderBox {
if (_rowDecorationPainters != null) {
for (BoxPainter painter in _rowDecorationPainters)
painter?.dispose();
_rowDecorationPainters = null;
_rowDecorationPainters = List<BoxPainter>(_rowDecorations.length);
}
for (RenderBox child in _children)
child?.detach();
......@@ -1137,6 +1139,7 @@ class RenderTable extends RenderBox {
}
assert(_rowTops.length == rows + 1);
if (_rowDecorations != null) {
assert(_rowDecorations.length == _rowDecorationPainters.length);
final Canvas canvas = context.canvas;
for (int y = 0; y < rows; y += 1) {
if (_rowDecorations.length <= y)
......
......@@ -5,6 +5,7 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
class TestStatefulWidget extends StatefulWidget {
const TestStatefulWidget({ Key key }) : super(key: key);
......@@ -67,6 +68,41 @@ void main() {
await run(TextDirection.rtl);
});
testWidgets('Table widget can be detached and re-attached', (WidgetTester tester) async {
final Widget table = Table(
key: GlobalKey(),
children: const <TableRow>[
TableRow(
decoration: BoxDecoration(
color: Colors.yellow
),
children: <Widget>[Placeholder()],
),
],
);
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: table,
),
),
);
// Move table to a different location to simulate detaching and re-attaching effect.
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Center(
child: table
),
),
),
);
expect(tester.takeException(), isNull);
});
testWidgets('Table widget - column offset (LTR)', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment