Skip to content

Commit 6d38831

Browse files
authored
Test of AppBarMediumApp and AppBarLargeApp (flutter#153973)
Part of flutter#130459 This are tests of snippets used in [SliverAppBar.medium const constructor](https://api.flutter.dev/flutter/material/SliverAppBar/SliverAppBar.medium.html) and [SliverAppBar.large const constructor](https://api.flutter.dev/flutter/material/SliverAppBar/SliverAppBar.large.html) Flutter API reference documentation. The only way I've found to distinguish the SliverAppBar.medium and SliverAppBar.large constructors from the regular SliverAppBar is to check if the title is styled according to the [Material Design 3](https://m3.material.io/components/top-app-bar/specs) specification.
1 parent b99322e commit 6d38831

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,6 @@ final Set<String> _knownMissingTests = <String>{
319319
'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart',
320320
'examples/api/test/material/platform_menu_bar/platform_menu_bar.0_test.dart',
321321
'examples/api/test/material/flexible_space_bar/flexible_space_bar.0_test.dart',
322-
'examples/api/test/material/app_bar/sliver_app_bar.2_test.dart',
323-
'examples/api/test/material/app_bar/sliver_app_bar.3_test.dart',
324322
'examples/api/test/material/navigation_rail/navigation_rail.extended_animation.0_test.dart',
325323
'examples/api/test/painting/star_border/star_border.0_test.dart',
326324
'examples/api/test/widgets/navigator/navigator.restorable_push_and_remove_until.0_test.dart',
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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/material/app_bar/sliver_app_bar.2.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Visibility and interaction of crucial widgets', (WidgetTester tester) async {
11+
await tester.pumpWidget(const example.AppBarMediumApp());
12+
13+
const String title = 'Medium App Bar';
14+
15+
expect(find.descendant(
16+
of: find.byType(CustomScrollView),
17+
matching: find.widgetWithText(SliverAppBar, title),
18+
), findsOne);
19+
20+
expect(find.descendant(
21+
of: find.byType(SliverAppBar),
22+
matching: find.byType(IconButton),
23+
), findsExactly(2));
24+
25+
// Based on https://m3.material.io/components/top-app-bar/specs the title of
26+
// the SliverAppBar.medium widget is formatted with the headlineSmall style.
27+
final BuildContext context = tester.element(find.byType(MaterialApp));
28+
final TextStyle expectedTitleStyle = Theme.of(context).textTheme.headlineSmall!;
29+
30+
// There are two Text widgets: expanded and collapsed. The expanded is first.
31+
final Finder titleFinder = find.text(title).first;
32+
final TextStyle actualTitleStyle = DefaultTextStyle.of(tester.element(titleFinder)).style;
33+
34+
expect(actualTitleStyle, expectedTitleStyle);
35+
36+
// Scrolling the screen moves the title up.
37+
expect(tester.getBottomLeft(titleFinder).dy, 96.0);
38+
await tester.drag(titleFinder, const Offset(0.0, -200.0));
39+
await tester.pump();
40+
expect(tester.getBottomLeft(titleFinder).dy, 48.0);
41+
});
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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/material/app_bar/sliver_app_bar.3.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Visibility and interaction of crucial widgets', (WidgetTester tester) async {
11+
await tester.pumpWidget(const example.AppBarLargeApp());
12+
13+
const String title = 'Large App Bar';
14+
15+
expect(find.descendant(
16+
of: find.byType(CustomScrollView),
17+
matching: find.widgetWithText(SliverAppBar, title),
18+
), findsOne);
19+
20+
expect(find.descendant(
21+
of: find.byType(SliverAppBar),
22+
matching: find.byType(IconButton),
23+
), findsExactly(2));
24+
25+
// Based on https://m3.material.io/components/top-app-bar/specs the title of
26+
// the SliverAppBar.large widget is formatted with the headlineMedium style.
27+
final BuildContext context = tester.element(find.byType(MaterialApp));
28+
final TextStyle expectedTitleStyle = Theme.of(context).textTheme.headlineMedium!;
29+
30+
// There are two Text widgets: expanded and collapsed. The expanded is first.
31+
final Finder titleFinder = find.text(title).first;
32+
final TextStyle actualTitleStyle = DefaultTextStyle.of(tester.element(titleFinder)).style;
33+
34+
expect(actualTitleStyle, expectedTitleStyle);
35+
36+
// Scrolling the screen moves the title up.
37+
expect(tester.getBottomLeft(titleFinder).dy, 124.0);
38+
await tester.drag(titleFinder, const Offset(0.0, -200.0));
39+
await tester.pump();
40+
expect(tester.getBottomLeft(titleFinder).dy, 36.0);
41+
});
42+
}

0 commit comments

Comments
 (0)