File tree Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -348,7 +348,8 @@ class SliverGridDelegateWithFixedCrossAxisCount extends SliverGridDelegate {
348348 }) : assert (crossAxisCount > 0 ),
349349 assert (mainAxisSpacing >= 0 ),
350350 assert (crossAxisSpacing >= 0 ),
351- assert (childAspectRatio > 0 );
351+ assert (childAspectRatio > 0 ),
352+ assert (mainAxisExtent == null || mainAxisExtent >= 0 );
352353
353354 /// The number of children in the cross axis.
354355 final int crossAxisCount;
@@ -446,7 +447,8 @@ class SliverGridDelegateWithMaxCrossAxisExtent extends SliverGridDelegate {
446447 }) : assert (maxCrossAxisExtent > 0 ),
447448 assert (mainAxisSpacing >= 0 ),
448449 assert (crossAxisSpacing >= 0 ),
449- assert (childAspectRatio > 0 );
450+ assert (childAspectRatio > 0 ),
451+ assert (mainAxisExtent == null || mainAxisExtent >= 0 );
450452
451453 /// The maximum extent of tiles in the cross axis.
452454 ///
Original file line number Diff line number Diff line change @@ -898,4 +898,48 @@ void main() {
898898 expect (controller.position.maxScrollExtent, 472.0 );
899899 expect (controller.position.pixels, 472.0 );
900900 });
901+
902+ testWidgets ('SliverGridDelegate mainAxisExtent add assert' ,
903+ (WidgetTester tester) async {
904+ Widget buildGridView (SliverGridDelegate delegate) {
905+ return Directionality (
906+ textDirection: TextDirection .ltr,
907+ child: GridView .builder (
908+ gridDelegate: delegate,
909+ itemBuilder: (BuildContext context, int index) {
910+ return Container (
911+ height: 50 ,
912+ alignment: Alignment .center,
913+ child: Text ('$index ' ),
914+ );
915+ },
916+ itemCount: 50 ,
917+ ),
918+ );
919+ }
920+
921+ expect (
922+ () => tester.pumpWidget (buildGridView (
923+ SliverGridDelegateWithFixedCrossAxisCount (
924+ crossAxisCount: 3 ,
925+ mainAxisSpacing: 8 ,
926+ crossAxisSpacing: 8 ,
927+ mainAxisExtent: - 100 ,
928+ ),
929+ )),
930+ throwsA (isA <AssertionError >()),
931+ );
932+
933+ expect (
934+ () => tester.pumpWidget (buildGridView (
935+ SliverGridDelegateWithMaxCrossAxisExtent (
936+ maxCrossAxisExtent: 100 ,
937+ mainAxisSpacing: 8 ,
938+ crossAxisSpacing: 8 ,
939+ mainAxisExtent: - 100 ,
940+ ),
941+ )),
942+ throwsA (isA <AssertionError >()),
943+ );
944+ });
901945}
You can’t perform that action at this time.
0 commit comments