File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Expand file tree Collapse file tree 2 files changed +53
-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,53 @@ void main() {
898898 expect (controller.position.maxScrollExtent, 472.0 );
899899 expect (controller.position.pixels, 472.0 );
900900 });
901+
902+ testWidgets ('SliverGridDelegate mainAxisExtent add assert' , (WidgetTester tester) async {
903+ Widget buildGridView (SliverGridDelegate delegate) {
904+ return Directionality (
905+ textDirection: TextDirection .ltr,
906+ child: GridView .builder (
907+ gridDelegate: delegate,
908+ itemBuilder: (BuildContext context, int index) {
909+ return Container (
910+ height: 50 ,
911+ alignment: Alignment .center,
912+ child: Text ('$index ' ),
913+ );
914+ },
915+ itemCount: 50 ,
916+ ),
917+ );
918+ }
919+
920+ expect (
921+ () => tester.pumpWidget (buildGridView (SliverGridDelegateWithFixedCrossAxisCount (
922+ crossAxisCount: 3 ,
923+ mainAxisSpacing: 8 ,
924+ crossAxisSpacing: 8 ,
925+ mainAxisExtent: - 100 ,
926+ ))),
927+ throwsA (isAssertionError.having (
928+ (AssertionError e) => e.toString (),
929+ '.toString()' ,
930+ contains ("'mainAxisExtent == null || mainAxisExtent >= 0': is not true." ),
931+ )),
932+ );
933+
934+ expect (
935+ () => tester.pumpWidget (buildGridView (SliverGridDelegateWithMaxCrossAxisExtent (
936+ maxCrossAxisExtent: 100 ,
937+ mainAxisSpacing: 8 ,
938+ crossAxisSpacing: 8 ,
939+ mainAxisExtent: - 100 ,
940+ ))),
941+ throwsA (isAssertionError.having (
942+ (AssertionError e) => e.toString (),
943+ '.toString()' ,
944+ contains ("'mainAxisExtent == null || mainAxisExtent >= 0': is not true." ),
945+ )),
946+ );
947+ });
948+
949+
901950}
You can’t perform that action at this time.
0 commit comments