Fix two dimensional viewport unexpected null exception when no child is laid out (#148256)
- Fixes #148255
This commit is contained in:
@@ -1318,7 +1318,9 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA
|
||||
}
|
||||
}
|
||||
_lastChild = previousChild;
|
||||
parentDataOf(_lastChild!)._nextSibling = null;
|
||||
if (_lastChild != null) {
|
||||
parentDataOf(_lastChild!)._nextSibling = null;
|
||||
}
|
||||
// Reset for next layout pass.
|
||||
_leadingXIndex = null;
|
||||
_trailingXIndex = null;
|
||||
|
||||
@@ -237,12 +237,12 @@ class RenderSimpleBuilderTableViewport extends RenderTwoDimensionalViewport {
|
||||
double yLayoutOffset = (leadingRow * 200) - verticalOffset.pixels;
|
||||
for (int row = leadingRow; row <= trailingRow; row++) {
|
||||
final ChildVicinity vicinity = ChildVicinity(xIndex: column, yIndex: row);
|
||||
final RenderBox child = buildOrObtainChildFor(vicinity)!;
|
||||
final RenderBox? child = buildOrObtainChildFor(vicinity);
|
||||
if (!forgetToLayoutChild) {
|
||||
child.layout(constraints.tighten(width: 200.0, height: 200.0));
|
||||
child?.layout(constraints.tighten(width: 200.0, height: 200.0));
|
||||
}
|
||||
|
||||
if (setLayoutOffset) {
|
||||
if (setLayoutOffset && child != null) {
|
||||
parentDataOf(child).layoutOffset = Offset(xLayoutOffset, yLayoutOffset);
|
||||
}
|
||||
yLayoutOffset += 200;
|
||||
|
||||
@@ -2713,6 +2713,27 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('Does not throw when no child is laid out',
|
||||
(WidgetTester tester) async {
|
||||
final TwoDimensionalChildBuilderDelegate delegate =
|
||||
TwoDimensionalChildBuilderDelegate(
|
||||
maxXIndex: 50,
|
||||
maxYIndex: 50,
|
||||
addAutomaticKeepAlives: false,
|
||||
addRepaintBoundaries: false,
|
||||
builder: (BuildContext context, ChildVicinity vicinity) {
|
||||
if (vicinity.xIndex > 10) {
|
||||
return const SizedBox.square(dimension: 200);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
addTearDown(delegate.dispose);
|
||||
|
||||
await tester.pumpWidget(simpleBuilderTest(delegate: delegate));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('correctly reorders children and wont throw assertion failure',
|
||||
(WidgetTester tester) async {
|
||||
final TwoDimensionalChildBuilderDelegate delegate1 =
|
||||
|
||||
Reference in New Issue
Block a user