Reland: https://github.com/flutter/flutter/pull/148470 Fixes https://github.com/flutter/flutter/issues/138871
This commit is contained in:
@@ -348,7 +348,8 @@ class SliverGridDelegateWithFixedCrossAxisCount extends SliverGridDelegate {
|
||||
}) : assert(crossAxisCount > 0),
|
||||
assert(mainAxisSpacing >= 0),
|
||||
assert(crossAxisSpacing >= 0),
|
||||
assert(childAspectRatio > 0);
|
||||
assert(childAspectRatio > 0),
|
||||
assert(mainAxisExtent == null || mainAxisExtent >= 0);
|
||||
|
||||
/// The number of children in the cross axis.
|
||||
final int crossAxisCount;
|
||||
@@ -446,8 +447,8 @@ class SliverGridDelegateWithMaxCrossAxisExtent extends SliverGridDelegate {
|
||||
}) : assert(maxCrossAxisExtent > 0),
|
||||
assert(mainAxisSpacing >= 0),
|
||||
assert(crossAxisSpacing >= 0),
|
||||
assert(childAspectRatio > 0);
|
||||
|
||||
assert(childAspectRatio > 0),
|
||||
assert(mainAxisExtent == null || mainAxisExtent >= 0);
|
||||
/// The maximum extent of tiles in the cross axis.
|
||||
///
|
||||
/// This delegate will select a cross-axis extent for the tiles that is as
|
||||
|
||||
@@ -898,4 +898,61 @@ void main() {
|
||||
expect(controller.position.maxScrollExtent, 472.0);
|
||||
expect(controller.position.pixels, 472.0);
|
||||
});
|
||||
|
||||
testWidgets('SliverGridDelegate mainAxisExtent add assert', (WidgetTester tester) async {
|
||||
Widget buildGridView(SliverGridDelegate delegate) {
|
||||
return Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: GridView.builder(
|
||||
gridDelegate: delegate,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
height: 50,
|
||||
alignment: Alignment.center,
|
||||
child: Text('$index'),
|
||||
);
|
||||
},
|
||||
itemCount: 50,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
await expectLater(
|
||||
() => tester.pumpWidget(buildGridView(
|
||||
SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3,
|
||||
mainAxisSpacing: 8,
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisExtent: -100,
|
||||
),
|
||||
)),
|
||||
throwsA(
|
||||
isAssertionError.having(
|
||||
(AssertionError e) => e.toString(),
|
||||
'.toString()',
|
||||
contains('mainAxisExtent == null || mainAxisExtent >= 0'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
() => tester.pumpWidget(
|
||||
buildGridView(
|
||||
SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent: 100,
|
||||
mainAxisSpacing: 8,
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisExtent: -100,
|
||||
),
|
||||
),
|
||||
),
|
||||
throwsA(
|
||||
isAssertionError.having(
|
||||
(AssertionError e) => e.toString(),
|
||||
'.toString()',
|
||||
contains('mainAxisExtent == null || mainAxisExtent >= 0'),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user