Skip to content

Commit 15904ef

Browse files
Add tests for sliver grid delegate with fixed cross axis count examples (flutter#153500)
Contributes to flutter#130459 It adds a test for - `examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.0.dart` - `examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.1.dart` I also fixed a mistake in the documentation
1 parent 8f80d14 commit 15904ef

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,6 @@ final Set<String> _knownMissingTests = <String>{
322322
'examples/api/test/material/app_bar/sliver_app_bar.2_test.dart',
323323
'examples/api/test/material/app_bar/sliver_app_bar.3_test.dart',
324324
'examples/api/test/material/navigation_rail/navigation_rail.extended_animation.0_test.dart',
325-
'examples/api/test/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.0_test.dart',
326-
'examples/api/test/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.1_test.dart',
327325
'examples/api/test/painting/star_border/star_border.0_test.dart',
328326
'examples/api/test/widgets/navigator/navigator.restorable_push_and_remove_until.0_test.dart',
329327
'examples/api/test/widgets/navigator/navigator.restorable_push.0_test.dart',

examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.0.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SliverGridDelegateWithFixedCrossAxisCountExample extends StatelessWidget {
3030
return GridView(
3131
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
3232
crossAxisCount: 4,
33-
childAspectRatio: 0.5,
33+
childAspectRatio: 2,
3434
),
3535
children: List<Widget>.generate(20, (int i) {
3636
return Builder(builder: (BuildContext context) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_api_samples/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Each tiles should have a width of 200.0 and a height of 100.0', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.SliverGridDelegateWithFixedCrossAxisCountExampleApp(),
13+
);
14+
15+
for (int i = 0; i < 20; i++) {
16+
expect(find.text('$i'), findsOne);
17+
final Element element = tester.element(find.text('$i'));
18+
19+
expect(element.size, const Size(200, 100));
20+
}
21+
});
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_api_samples/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.1.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Each tiles should have a width of 200.0 and a height of 150.0', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.SliverGridDelegateWithFixedCrossAxisCountExampleApp(),
13+
);
14+
15+
for (int i = 0; i < 4; i++) {
16+
expect(find.text('$i'), findsOne);
17+
final Element element = tester.element(find.text('$i'));
18+
19+
expect(element.size, const Size(200, 150));
20+
}
21+
});
22+
}

0 commit comments

Comments
 (0)