Add tests for sliver grid delegate with fixed cross axis count examples (#153500)

Contributes to https://github.com/flutter/flutter/issues/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
This commit is contained in:
Valentin Vignal 2024-08-30 05:41:21 +08:00 committed by GitHub
parent 8f80d14e35
commit 15904ef9be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 3 deletions

View File

@ -322,8 +322,6 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/material/app_bar/sliver_app_bar.2_test.dart',
'examples/api/test/material/app_bar/sliver_app_bar.3_test.dart',
'examples/api/test/material/navigation_rail/navigation_rail.extended_animation.0_test.dart',
'examples/api/test/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.0_test.dart',
'examples/api/test/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.1_test.dart',
'examples/api/test/painting/star_border/star_border.0_test.dart',
'examples/api/test/widgets/navigator/navigator.restorable_push_and_remove_until.0_test.dart',
'examples/api/test/widgets/navigator/navigator.restorable_push.0_test.dart',

View File

@ -30,7 +30,7 @@ class SliverGridDelegateWithFixedCrossAxisCountExample extends StatelessWidget {
return GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
childAspectRatio: 0.5,
childAspectRatio: 2,
),
children: List<Widget>.generate(20, (int i) {
return Builder(builder: (BuildContext context) {

View File

@ -0,0 +1,22 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Each tiles should have a width of 200.0 and a height of 100.0', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverGridDelegateWithFixedCrossAxisCountExampleApp(),
);
for (int i = 0; i < 20; i++) {
expect(find.text('$i'), findsOne);
final Element element = tester.element(find.text('$i'));
expect(element.size, const Size(200, 100));
}
});
}

View File

@ -0,0 +1,22 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Each tiles should have a width of 200.0 and a height of 150.0', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverGridDelegateWithFixedCrossAxisCountExampleApp(),
);
for (int i = 0; i < 4; i++) {
expect(find.text('$i'), findsOne);
final Element element = tester.element(find.text('$i'));
expect(element.size, const Size(200, 150));
}
});
}