Unverified Commit ca319278 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix lower bound of children from TwoDimensionalChildBuilderDelegate (#132713)

Found in https://github.com/flutter/packages/pull/4536

The max x and max y index  should allow for a case where there are no children in the viewport.
This should be CP'd into stable once it lands.
parent 88643950
...@@ -933,8 +933,8 @@ class TwoDimensionalChildBuilderDelegate extends TwoDimensionalChildDelegate { ...@@ -933,8 +933,8 @@ class TwoDimensionalChildBuilderDelegate extends TwoDimensionalChildDelegate {
int? maxYIndex, int? maxYIndex,
this.addRepaintBoundaries = true, this.addRepaintBoundaries = true,
this.addAutomaticKeepAlives = true, this.addAutomaticKeepAlives = true,
}) : assert(maxYIndex == null || maxYIndex >= 0), }) : assert(maxYIndex == null || maxYIndex >= -1),
assert(maxXIndex == null || maxXIndex >= 0), assert(maxXIndex == null || maxXIndex >= -1),
_maxYIndex = maxYIndex, _maxYIndex = maxYIndex,
_maxXIndex = maxXIndex; _maxXIndex = maxXIndex;
...@@ -976,7 +976,9 @@ class TwoDimensionalChildBuilderDelegate extends TwoDimensionalChildDelegate { ...@@ -976,7 +976,9 @@ class TwoDimensionalChildBuilderDelegate extends TwoDimensionalChildDelegate {
/// [TwoDimensionalViewport] subclass to learn how this value is applied in /// [TwoDimensionalViewport] subclass to learn how this value is applied in
/// the specific use case. /// the specific use case.
/// ///
/// If not null, the value must be non-negative. /// If not null, the value must be greater than or equal to -1, where -1
/// indicates there will be no children at all provided to the
/// [TwoDimensionalViewport].
/// ///
/// If the value changes, the delegate will call [notifyListeners]. This /// If the value changes, the delegate will call [notifyListeners]. This
/// informs the [RenderTwoDimensionalViewport] that any cached information /// informs the [RenderTwoDimensionalViewport] that any cached information
...@@ -997,7 +999,7 @@ class TwoDimensionalChildBuilderDelegate extends TwoDimensionalChildDelegate { ...@@ -997,7 +999,7 @@ class TwoDimensionalChildBuilderDelegate extends TwoDimensionalChildDelegate {
if (value == maxXIndex) { if (value == maxXIndex) {
return; return;
} }
assert(value == null || value >= 0); assert(value == null || value >= -1);
_maxXIndex = value; _maxXIndex = value;
notifyListeners(); notifyListeners();
} }
...@@ -1020,7 +1022,7 @@ class TwoDimensionalChildBuilderDelegate extends TwoDimensionalChildDelegate { ...@@ -1020,7 +1022,7 @@ class TwoDimensionalChildBuilderDelegate extends TwoDimensionalChildDelegate {
if (maxYIndex == value) { if (maxYIndex == value) {
return; return;
} }
assert(value == null || value >= 0); assert(value == null || value >= -1);
_maxYIndex = value; _maxYIndex = value;
notifyListeners(); notifyListeners();
} }
......
...@@ -120,27 +120,29 @@ void main() { ...@@ -120,27 +120,29 @@ void main() {
} }
); );
// Update // Update
delegate.maxXIndex = -1; // No exception.
expect( expect(
() { () {
delegate.maxXIndex = -1; delegate.maxXIndex = -2;
}, },
throwsA( throwsA(
isA<AssertionError>().having( isA<AssertionError>().having(
(AssertionError error) => error.toString(), (AssertionError error) => error.toString(),
'description', 'description',
contains('value == null || value >= 0'), contains('value == null || value >= -1'),
), ),
), ),
); );
delegate.maxYIndex = -1; // No exception
expect( expect(
() { () {
delegate.maxYIndex = -1; delegate.maxYIndex = -2;
}, },
throwsA( throwsA(
isA<AssertionError>().having( isA<AssertionError>().having(
(AssertionError error) => error.toString(), (AssertionError error) => error.toString(),
'description', 'description',
contains('value == null || value >= 0'), contains('value == null || value >= -1'),
), ),
), ),
); );
...@@ -148,7 +150,7 @@ void main() { ...@@ -148,7 +150,7 @@ void main() {
expect( expect(
() { () {
TwoDimensionalChildBuilderDelegate( TwoDimensionalChildBuilderDelegate(
maxXIndex: -1, maxXIndex: -2,
maxYIndex: 0, maxYIndex: 0,
builder: (BuildContext context, ChildVicinity vicinity) { builder: (BuildContext context, ChildVicinity vicinity) {
return const SizedBox.shrink(); return const SizedBox.shrink();
...@@ -159,7 +161,7 @@ void main() { ...@@ -159,7 +161,7 @@ void main() {
isA<AssertionError>().having( isA<AssertionError>().having(
(AssertionError error) => error.toString(), (AssertionError error) => error.toString(),
'description', 'description',
contains('maxXIndex == null || maxXIndex >= 0'), contains('maxXIndex == null || maxXIndex >= -1'),
), ),
), ),
); );
...@@ -167,7 +169,7 @@ void main() { ...@@ -167,7 +169,7 @@ void main() {
() { () {
TwoDimensionalChildBuilderDelegate( TwoDimensionalChildBuilderDelegate(
maxXIndex: 0, maxXIndex: 0,
maxYIndex: -1, maxYIndex: -2,
builder: (BuildContext context, ChildVicinity vicinity) { builder: (BuildContext context, ChildVicinity vicinity) {
return const SizedBox.shrink(); return const SizedBox.shrink();
} }
...@@ -177,7 +179,7 @@ void main() { ...@@ -177,7 +179,7 @@ void main() {
isA<AssertionError>().having( isA<AssertionError>().having(
(AssertionError error) => error.toString(), (AssertionError error) => error.toString(),
'description', 'description',
contains('maxYIndex == null || maxYIndex >= 0'), contains('maxYIndex == null || maxYIndex >= -1'),
), ),
), ),
); );
......
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