@@ -900,16 +900,20 @@ void main() {
900
900
expect (controller.position.pixels, 472.0 );
901
901
});
902
902
903
- testWidgets ('SliverGridDelegateWithFixedCrossAxisCount mainAxisExtent corrected' , (WidgetTester tester) async {
903
+ testWidgets (
904
+ 'SliverGridDelegateWithFixedCrossAxisCount mainAxisExtent corrected' ,
905
+ (WidgetTester tester) async {
904
906
// Regression test for https://github.com/flutter/flutter/issues/138871
905
- const SliverGridDelegateWithFixedCrossAxisCount delegate = SliverGridDelegateWithFixedCrossAxisCount (
907
+ const SliverGridDelegateWithFixedCrossAxisCount delegate =
908
+ SliverGridDelegateWithFixedCrossAxisCount (
906
909
crossAxisCount: 3 ,
907
910
mainAxisSpacing: 8 ,
908
911
crossAxisSpacing: 8 ,
909
912
mainAxisExtent: - 100 ,
910
913
);
911
914
912
- final SliverGridRegularTileLayout sliverGridRegularTileLayout = delegate.getLayout (
915
+ final SliverGridRegularTileLayout sliverGridRegularTileLayout =
916
+ delegate.getLayout (
913
917
const SliverConstraints (
914
918
axisDirection: AxisDirection .down,
915
919
growthDirection: GrowthDirection .forward,
@@ -927,18 +931,54 @@ void main() {
927
931
) as SliverGridRegularTileLayout ;
928
932
929
933
expect (sliverGridRegularTileLayout.childMainAxisExtent, 0 );
934
+
935
+ double mainAxisExtent = 100 ;
936
+ late StateSetter stateSetter;
937
+ await tester.pumpWidget (Directionality (
938
+ textDirection: TextDirection .ltr,
939
+ child: StatefulBuilder (
940
+ builder: (BuildContext context, StateSetter setState) {
941
+ stateSetter = setState;
942
+ return GridView .builder (
943
+ gridDelegate: SliverGridDelegateWithFixedCrossAxisCount (
944
+ crossAxisCount: 3 ,
945
+ mainAxisSpacing: 8 ,
946
+ crossAxisSpacing: 8 ,
947
+ mainAxisExtent: mainAxisExtent,
948
+ ),
949
+ itemBuilder: (BuildContext context, int index) {
950
+ return Container (
951
+ height: 50 ,
952
+ alignment: Alignment .center,
953
+ child: Text ('$index ' ),
954
+ );
955
+ },
956
+ );
957
+ },
958
+ ),
959
+ ));
960
+ expect (tester.takeException (), isNull);
961
+
962
+ stateSetter (() => mainAxisExtent = - 100 );
963
+ await tester.pump ();
964
+
965
+ expect (tester.takeException (), isNull);
930
966
});
931
967
932
- testWidgets ('SliverGridDelegateWithMaxCrossAxisExtent mainAxisExtent corrected' , (WidgetTester tester) async {
968
+ testWidgets (
969
+ 'SliverGridDelegateWithMaxCrossAxisExtent mainAxisExtent corrected' ,
970
+ (WidgetTester tester) async {
933
971
// Regression test for https://github.com/flutter/flutter/issues/138871
934
- const SliverGridDelegateWithMaxCrossAxisExtent delegate = SliverGridDelegateWithMaxCrossAxisExtent (
972
+ const SliverGridDelegateWithMaxCrossAxisExtent delegate =
973
+ SliverGridDelegateWithMaxCrossAxisExtent (
935
974
maxCrossAxisExtent: 100 ,
936
975
mainAxisSpacing: 8 ,
937
976
crossAxisSpacing: 8 ,
938
977
mainAxisExtent: - 100 ,
939
978
);
940
979
941
- final SliverGridRegularTileLayout sliverGridRegularTileLayout = delegate.getLayout (
980
+ final SliverGridRegularTileLayout sliverGridRegularTileLayout =
981
+ delegate.getLayout (
942
982
const SliverConstraints (
943
983
axisDirection: AxisDirection .down,
944
984
growthDirection: GrowthDirection .forward,
@@ -956,5 +996,37 @@ void main() {
956
996
) as SliverGridRegularTileLayout ;
957
997
958
998
expect (sliverGridRegularTileLayout.childMainAxisExtent, 0 );
999
+
1000
+ double mainAxisExtent = 100 ;
1001
+ late StateSetter stateSetter;
1002
+ await tester.pumpWidget (Directionality (
1003
+ textDirection: TextDirection .ltr,
1004
+ child: StatefulBuilder (
1005
+ builder: (BuildContext context, StateSetter setState) {
1006
+ stateSetter = setState;
1007
+ return GridView .builder (
1008
+ gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent (
1009
+ maxCrossAxisExtent: 100 ,
1010
+ mainAxisSpacing: 8 ,
1011
+ crossAxisSpacing: 8 ,
1012
+ mainAxisExtent: mainAxisExtent,
1013
+ ),
1014
+ itemBuilder: (BuildContext context, int index) {
1015
+ return Container (
1016
+ height: 50 ,
1017
+ alignment: Alignment .center,
1018
+ child: Text ('$index ' ),
1019
+ );
1020
+ },
1021
+ );
1022
+ },
1023
+ ),
1024
+ ));
1025
+ expect (tester.takeException (), isNull);
1026
+
1027
+ stateSetter (() => mainAxisExtent = - 100 );
1028
+ await tester.pump ();
1029
+
1030
+ expect (tester.takeException (), isNull);
959
1031
});
960
1032
}
0 commit comments