@@ -111,6 +111,78 @@ void main() {
111
111
);
112
112
}, variant: TargetPlatformVariant .all ());
113
113
114
+ test ('maxXIndex and maxYIndex assertions' , () {
115
+ final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate (
116
+ maxXIndex: 0 ,
117
+ maxYIndex: 0 ,
118
+ builder: (BuildContext context, ChildVicinity vicinity) {
119
+ return const SizedBox .shrink ();
120
+ }
121
+ );
122
+ // Update
123
+ expect (
124
+ () {
125
+ delegate.maxXIndex = - 1 ;
126
+ },
127
+ throwsA (
128
+ isA <AssertionError >().having (
129
+ (AssertionError error) => error.toString (),
130
+ 'description' ,
131
+ contains ('value == null || value >= 0' ),
132
+ ),
133
+ ),
134
+ );
135
+ expect (
136
+ () {
137
+ delegate.maxYIndex = - 1 ;
138
+ },
139
+ throwsA (
140
+ isA <AssertionError >().having (
141
+ (AssertionError error) => error.toString (),
142
+ 'description' ,
143
+ contains ('value == null || value >= 0' ),
144
+ ),
145
+ ),
146
+ );
147
+ // Constructor
148
+ expect (
149
+ () {
150
+ TwoDimensionalChildBuilderDelegate (
151
+ maxXIndex: - 1 ,
152
+ maxYIndex: 0 ,
153
+ builder: (BuildContext context, ChildVicinity vicinity) {
154
+ return const SizedBox .shrink ();
155
+ }
156
+ );
157
+ },
158
+ throwsA (
159
+ isA <AssertionError >().having (
160
+ (AssertionError error) => error.toString (),
161
+ 'description' ,
162
+ contains ('maxXIndex == null || maxXIndex >= 0' ),
163
+ ),
164
+ ),
165
+ );
166
+ expect (
167
+ () {
168
+ TwoDimensionalChildBuilderDelegate (
169
+ maxXIndex: 0 ,
170
+ maxYIndex: - 1 ,
171
+ builder: (BuildContext context, ChildVicinity vicinity) {
172
+ return const SizedBox .shrink ();
173
+ }
174
+ );
175
+ },
176
+ throwsA (
177
+ isA <AssertionError >().having (
178
+ (AssertionError error) => error.toString (),
179
+ 'description' ,
180
+ contains ('maxYIndex == null || maxYIndex >= 0' ),
181
+ ),
182
+ ),
183
+ );
184
+ });
185
+
114
186
testWidgets ('throws an error when builder throws' , (WidgetTester tester) async {
115
187
final List <Object > exceptions = < Object > [];
116
188
final FlutterExceptionHandler ? oldHandler = FlutterError .onError;
@@ -1822,3 +1894,28 @@ Future<void> restoreScrollAndVerify(WidgetTester tester) async {
1822
1894
100.0 ,
1823
1895
);
1824
1896
}
1897
+
1898
+ // Validates covariant through analysis.
1899
+ mixin _SomeDelegateMixin on TwoDimensionalChildDelegate {}
1900
+
1901
+ class _SomeRenderTwoDimensionalViewport extends RenderTwoDimensionalViewport { // ignore: unused_element
1902
+ _SomeRenderTwoDimensionalViewport ({
1903
+ required super .horizontalOffset,
1904
+ required super .horizontalAxisDirection,
1905
+ required super .verticalOffset,
1906
+ required super .verticalAxisDirection,
1907
+ required _SomeDelegateMixin super .delegate,
1908
+ required super .mainAxis,
1909
+ required super .childManager,
1910
+ });
1911
+
1912
+ @override
1913
+ _SomeDelegateMixin get delegate => super .delegate as _SomeDelegateMixin ;
1914
+ @override
1915
+ set delegate (_SomeDelegateMixin value) { // Analysis would fail without covariant
1916
+ super .delegate = value;
1917
+ }
1918
+
1919
+ @override
1920
+ void layoutChildSequence () {}
1921
+ }
0 commit comments