mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
More table fixes
This commit is contained in:
parent
b1ed094965
commit
bdfeaaa47a
@ -491,7 +491,7 @@ class RenderTable extends RenderBox {
|
||||
assert(_rows == 0);
|
||||
return;
|
||||
}
|
||||
for (RenderBox oldChild in cells) {
|
||||
for (RenderBox oldChild in _children) {
|
||||
if (oldChild != null)
|
||||
dropChild(oldChild);
|
||||
}
|
||||
@ -503,8 +503,8 @@ class RenderTable extends RenderBox {
|
||||
assert(cells != null);
|
||||
assert(cells.length % columns == 0);
|
||||
// remove cells that are moving away
|
||||
for (int y = 0; y < _columns; y += 1) {
|
||||
for (int x = 0; x < _rows; x += 1) {
|
||||
for (int y = 0; y < _rows; y += 1) {
|
||||
for (int x = 0; x < _columns; x += 1) {
|
||||
int xyOld = x + y * _columns;
|
||||
int xyNew = x + y * columns;
|
||||
if (_children[xyOld] != null && (x >= columns || xyNew >= cells.length || _children[xyOld] != cells[xyNew]))
|
||||
@ -567,6 +567,8 @@ class RenderTable extends RenderBox {
|
||||
assert(_children.length == rows * columns);
|
||||
final int xy = x + y * columns;
|
||||
RenderBox oldChild = _children[xy];
|
||||
if (oldChild == value)
|
||||
return;
|
||||
if (oldChild != null)
|
||||
dropChild(oldChild);
|
||||
_children[xy] = value;
|
||||
@ -759,6 +761,7 @@ class RenderTable extends RenderBox {
|
||||
RenderBox child = _children[xy];
|
||||
if (child != null) {
|
||||
TableCellParentData childParentData = child.parentData;
|
||||
assert(childParentData != null);
|
||||
childParentData.x = x;
|
||||
childParentData.y = y;
|
||||
switch (childParentData.verticalAlignment ?? defaultVerticalAlignment) {
|
||||
|
||||
@ -71,4 +71,24 @@ void main() {
|
||||
table.rows = 4;
|
||||
expect(child.attached, isFalse);
|
||||
});
|
||||
|
||||
test('Table test: replacing cells', () {
|
||||
RenderTable table;
|
||||
RenderBox child1 = new RenderPositionedBox();
|
||||
RenderBox child2 = new RenderPositionedBox();
|
||||
RenderBox child3 = new RenderPositionedBox();
|
||||
table = new RenderTable();
|
||||
table.setFlatChildren(3, <RenderBox>[child1, new RenderPositionedBox(), child2,
|
||||
new RenderPositionedBox(), child3, new RenderPositionedBox()]);
|
||||
expect(table.rows, equals(2));
|
||||
layout(table);
|
||||
table.setFlatChildren(3, <RenderBox>[new RenderPositionedBox(), child1, new RenderPositionedBox(),
|
||||
child2, new RenderPositionedBox(), child3]);
|
||||
layout(table);
|
||||
table.setFlatChildren(3, <RenderBox>[new RenderPositionedBox(), child1, new RenderPositionedBox(),
|
||||
child2, new RenderPositionedBox(), child3]);
|
||||
layout(table);
|
||||
expect(table.columns, equals(3));
|
||||
expect(table.rows, equals(2));
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user