Skip to content

Commit 4549081

Browse files
authored
Add app bar and tab bar to a11y assessment app (#152904)
*Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.* *List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.* *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
1 parent d7b092e commit 4549081

File tree

5 files changed

+221
-0
lines changed

5 files changed

+221
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
7+
import 'use_cases.dart';
8+
9+
class AppBarUseCase extends UseCase {
10+
@override
11+
String get name => 'AppBar';
12+
13+
@override
14+
String get route => '/app-bar';
15+
16+
@override
17+
Widget build(BuildContext context) => const MainWidget();
18+
}
19+
20+
class MainWidget extends StatefulWidget {
21+
const MainWidget({super.key});
22+
23+
@override
24+
State<MainWidget> createState() => MainWidgetState();
25+
}
26+
27+
class MainWidgetState extends State<MainWidget> {
28+
int currentIndex = 0;
29+
30+
void _onChanged(int? value) {
31+
setState(() {
32+
currentIndex = value!;
33+
});
34+
}
35+
36+
@override
37+
Widget build(BuildContext context) {
38+
return Scaffold(
39+
appBar: <PreferredSizeWidget>[
40+
AppBar(
41+
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
42+
title: Semantics(headingLevel: 1, child: const Text('AppBar')),
43+
),
44+
AppBar(
45+
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
46+
title: Semantics(headingLevel: 1, child: const Text('AppBar')),
47+
actions: <Widget>[
48+
IconButton(
49+
icon: const Icon(Icons.add_alert),
50+
tooltip: 'Show Snackbar',
51+
onPressed: () {
52+
ScaffoldMessenger.of(context).showSnackBar(
53+
const SnackBar(content: Text('This is a snackbar')));
54+
},
55+
),
56+
IconButton(
57+
icon: const Icon(Icons.navigate_next),
58+
tooltip: 'Go to the next page',
59+
onPressed: () {
60+
Navigator.push(context, MaterialPageRoute<void>(
61+
builder: (BuildContext context) {
62+
return Scaffold(
63+
appBar: AppBar(
64+
backgroundColor:
65+
Theme.of(context).colorScheme.inversePrimary,
66+
title: Semantics(headingLevel: 1, child: const Text('Next Page')),
67+
),
68+
body: const Center(
69+
child: Text(
70+
'This is the next page',
71+
style: TextStyle(fontSize: 24),
72+
),
73+
),
74+
);
75+
},
76+
));
77+
},
78+
),
79+
],
80+
),
81+
AppBar(
82+
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
83+
title: Semantics(headingLevel: 1, child: const Text('AppBar')),
84+
actions: <Widget>[
85+
TextButton(
86+
onPressed: () {},
87+
child: const Text('Action 1'),
88+
),
89+
TextButton(
90+
onPressed: () {},
91+
child: const Text('Action 2'),
92+
),
93+
],
94+
),
95+
][currentIndex],
96+
body: ListView(
97+
children: <Widget>[
98+
RadioListTile<int>(
99+
title: const Text('1. Simple app bar'),
100+
value: 0,
101+
groupValue: currentIndex,
102+
onChanged: _onChanged,
103+
),
104+
RadioListTile<int>(
105+
title: const Text('2. App bar with actions'),
106+
value: 1,
107+
groupValue: currentIndex,
108+
onChanged: _onChanged,
109+
),
110+
RadioListTile<int>(
111+
title: const Text('3. App bar with text buttons'),
112+
value: 2,
113+
groupValue: currentIndex,
114+
onChanged: _onChanged,
115+
),
116+
],
117+
),
118+
);
119+
}
120+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
7+
import 'use_cases.dart';
8+
9+
class TabBarViewUseCase extends UseCase {
10+
11+
@override
12+
String get name => 'TabBarView';
13+
14+
@override
15+
String get route => '/tab-bar-view';
16+
17+
@override
18+
Widget build(BuildContext context) => const TabBarViewExample();
19+
}
20+
21+
22+
class TabBarViewExample extends StatelessWidget {
23+
const TabBarViewExample({super.key});
24+
25+
@override
26+
Widget build(BuildContext context) {
27+
return DefaultTabController(
28+
initialIndex: 1,
29+
length: 3,
30+
child: Scaffold(
31+
appBar: AppBar(
32+
title: Semantics(headingLevel: 1, child: const Text('TabBarView Sample')),
33+
bottom: const TabBar(
34+
tabs: <Widget>[
35+
Tab(
36+
icon: Icon(Icons.cloud_outlined),
37+
text: 'Cloudy',
38+
),
39+
Tab(
40+
icon: Icon(Icons.beach_access_sharp),
41+
text: 'Rainy',
42+
),
43+
Tab(
44+
icon: Icon(Icons.brightness_5_sharp),
45+
text: 'Sunny',
46+
),
47+
],
48+
),
49+
),
50+
body: const TabBarView(
51+
children: <Widget>[
52+
Center(
53+
child: Text("It's cloudy here"),
54+
),
55+
Center(
56+
child: Text("It's rainy here"),
57+
),
58+
Center(
59+
child: Text("It's sunny here"),
60+
),
61+
],
62+
),
63+
),
64+
);
65+
}
66+
}

dev/a11y_assessments/lib/use_cases/use_cases.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/widgets.dart';
66

77
import '../common/dynamic_title.dart';
88
import 'action_chip.dart';
9+
import 'app_bar.dart';
910
import 'auto_complete.dart';
1011
import 'badge.dart';
1112
import 'card.dart';
@@ -22,6 +23,7 @@ import 'radio_list_tile.dart';
2223
import 'slider.dart';
2324
import 'snack_bar.dart';
2425
import 'switch_list_tile.dart';
26+
import 'tab_bar_view.dart';
2527
import 'text_button.dart';
2628
import 'text_field.dart';
2729
import 'text_field_password.dart';
@@ -61,4 +63,6 @@ final List<UseCase> useCases = <UseCase>[
6163
DrawerUseCase(),
6264
NavigationDrawerUseCase(),
6365
NavigationRailUseCase(),
66+
AppBarUseCase(),
67+
TabBarViewUseCase(),
6468
];
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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:a11y_assessments/use_cases/app_bar.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
8+
import 'test_utils.dart';
9+
10+
void main() {
11+
testWidgets('app bar can run', (WidgetTester tester) async {
12+
await pumpsUseCase(tester, AppBarUseCase());
13+
expect(find.text('AppBar'), findsOneWidget);
14+
});
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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:a11y_assessments/use_cases/tab_bar_view.dart';
6+
import 'package:flutter/material.dart';
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
import 'test_utils.dart';
10+
11+
void main() {
12+
testWidgets('tab bar view can run', (WidgetTester tester) async {
13+
await pumpsUseCase(tester, TabBarViewUseCase());
14+
expect(find.byType(TabBar), findsOneWidget);
15+
});
16+
}

0 commit comments

Comments
 (0)