Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit cc256c3

Browse files
authored
Revert "Use semantics label for backbutton and closebutton for Android" (#116675)
This reverts commit 68ce1ae.
1 parent 68ce1ae commit cc256c3

File tree

4 files changed

+12
-134
lines changed

4 files changed

+12
-134
lines changed

packages/flutter/lib/src/material/back_button.dart

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:flutter/foundation.dart';
65
import 'package:flutter/widgets.dart';
76

87
import 'debug.dart';
@@ -28,39 +27,22 @@ class BackButtonIcon extends StatelessWidget {
2827
/// the current platform (as obtained from the [Theme]).
2928
const BackButtonIcon({ super.key });
3029

31-
@override
32-
Widget build(BuildContext context) {
33-
final String? semanticsLabel;
34-
final IconData data;
35-
switch (Theme.of(context).platform) {
36-
case TargetPlatform.android:
37-
case TargetPlatform.fuchsia:
38-
case TargetPlatform.linux:
39-
case TargetPlatform.windows:
40-
data = Icons.arrow_back;
41-
break;
42-
case TargetPlatform.iOS:
43-
case TargetPlatform.macOS:
44-
data = Icons.arrow_back_ios;
45-
break;
46-
}
47-
// This can't use the platform from Theme because it is the Android OS that
48-
// expects the duplicated tooltip and label.
49-
switch (defaultTargetPlatform) {
30+
/// Returns the appropriate "back" icon for the given `platform`.
31+
static IconData _getIconData(TargetPlatform platform) {
32+
switch (platform) {
5033
case TargetPlatform.android:
51-
semanticsLabel = MaterialLocalizations.of(context).backButtonTooltip;
52-
break;
5334
case TargetPlatform.fuchsia:
5435
case TargetPlatform.linux:
5536
case TargetPlatform.windows:
37+
return Icons.arrow_back;
5638
case TargetPlatform.iOS:
5739
case TargetPlatform.macOS:
58-
semanticsLabel = null;
59-
break;
40+
return Icons.arrow_back_ios;
6041
}
61-
62-
return Icon(data, semanticLabel: semanticsLabel);
6342
}
43+
44+
@override
45+
Widget build(BuildContext context) => Icon(_getIconData(Theme.of(context).platform));
6446
}
6547

6648
/// A Material Design back button.
@@ -167,23 +149,8 @@ class CloseButton extends StatelessWidget {
167149
@override
168150
Widget build(BuildContext context) {
169151
assert(debugCheckHasMaterialLocalizations(context));
170-
final String? semanticsLabel;
171-
// This can't use the platform from Theme because it is the Android OS that
172-
// expects the duplicated tooltip and label.
173-
switch (defaultTargetPlatform) {
174-
case TargetPlatform.android:
175-
semanticsLabel = MaterialLocalizations.of(context).closeButtonTooltip;
176-
break;
177-
case TargetPlatform.fuchsia:
178-
case TargetPlatform.linux:
179-
case TargetPlatform.windows:
180-
case TargetPlatform.iOS:
181-
case TargetPlatform.macOS:
182-
semanticsLabel = null;
183-
break;
184-
}
185152
return IconButton(
186-
icon: Icon(Icons.close, semanticLabel: semanticsLabel),
153+
icon: const Icon(Icons.close),
187154
color: color,
188155
tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
189156
onPressed: () {

packages/flutter/lib/src/widgets/semantics_debugger.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,10 @@ class _SemanticsDebuggerPainter extends CustomPainter {
288288

289289
assert(data.attributedLabel != null);
290290
final String message;
291-
// Android will avoid pronouncing duplicating tooltip and label.
292-
// Therefore, having two identical strings is the same as having a single
293-
// string.
294-
final bool shouldIgnoreDuplicatedLabel = defaultTargetPlatform == TargetPlatform.android && data.attributedLabel.string == data.tooltip;
295291
final String tooltipAndLabel = <String>[
296292
if (data.tooltip.isNotEmpty)
297293
data.tooltip,
298-
if (data.attributedLabel.string.isNotEmpty && !shouldIgnoreDuplicatedLabel)
294+
if (data.attributedLabel.string.isNotEmpty)
299295
data.attributedLabel.string,
300296
].join('\n');
301297
if (tooltipAndLabel.isEmpty) {

packages/flutter/test/material/back_button_test.dart

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:flutter/foundation.dart';
65
import 'package:flutter/material.dart';
76
import 'package:flutter_test/flutter_test.dart';
87

@@ -153,73 +152,17 @@ void main() {
153152
tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');
154153

155154
await tester.pumpAndSettle();
156-
final String? expectedLabel;
157-
switch(defaultTargetPlatform) {
158-
case TargetPlatform.android:
159-
expectedLabel = 'Back';
160-
break;
161-
case TargetPlatform.fuchsia:
162-
case TargetPlatform.iOS:
163-
case TargetPlatform.linux:
164-
case TargetPlatform.macOS:
165-
case TargetPlatform.windows:
166-
expectedLabel = null;
167-
}
155+
168156
expect(tester.getSemantics(find.byType(BackButton)), matchesSemantics(
169157
tooltip: 'Back',
170-
label: expectedLabel,
171-
isButton: true,
172-
hasEnabledState: true,
173-
isEnabled: true,
174-
hasTapAction: true,
175-
isFocusable: true,
176-
));
177-
handle.dispose();
178-
}, variant: TargetPlatformVariant.all());
179-
180-
testWidgets('CloseButton semantics', (WidgetTester tester) async {
181-
final SemanticsHandle handle = tester.ensureSemantics();
182-
await tester.pumpWidget(
183-
MaterialApp(
184-
home: const Material(child: Text('Home')),
185-
routes: <String, WidgetBuilder>{
186-
'/next': (BuildContext context) {
187-
return const Material(
188-
child: Center(
189-
child: CloseButton(),
190-
),
191-
);
192-
},
193-
},
194-
),
195-
);
196-
197-
tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');
198-
199-
await tester.pumpAndSettle();
200-
final String? expectedLabel;
201-
switch(defaultTargetPlatform) {
202-
case TargetPlatform.android:
203-
expectedLabel = 'Close';
204-
break;
205-
case TargetPlatform.fuchsia:
206-
case TargetPlatform.iOS:
207-
case TargetPlatform.linux:
208-
case TargetPlatform.macOS:
209-
case TargetPlatform.windows:
210-
expectedLabel = null;
211-
}
212-
expect(tester.getSemantics(find.byType(CloseButton)), matchesSemantics(
213-
tooltip: 'Close',
214-
label: expectedLabel,
215158
isButton: true,
216159
hasEnabledState: true,
217160
isEnabled: true,
218161
hasTapAction: true,
219162
isFocusable: true,
220163
));
221164
handle.dispose();
222-
}, variant: TargetPlatformVariant.all());
165+
});
223166

224167
testWidgets('CloseButton color', (WidgetTester tester) async {
225168
await tester.pumpWidget(

packages/flutter/test/widgets/semantics_debugger_test.dart

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:flutter/foundation.dart';
65
import 'package:flutter/material.dart';
76
import 'package:flutter_test/flutter_test.dart';
87

@@ -439,33 +438,6 @@ void main() {
439438
);
440439
});
441440

442-
testWidgets('SemanticsDebugger ignores duplicated label and tooltip for Android', (WidgetTester tester) async {
443-
final Key child = UniqueKey();
444-
final Key debugger = UniqueKey();
445-
final bool isPlatformAndroid = defaultTargetPlatform == TargetPlatform.android;
446-
await tester.pumpWidget(
447-
Directionality(
448-
textDirection: TextDirection.ltr,
449-
child: SemanticsDebugger(
450-
key: debugger,
451-
child: Material(
452-
child: Semantics(
453-
container: true,
454-
key: child,
455-
label: 'text',
456-
tooltip: 'text',
457-
),
458-
),
459-
),
460-
),
461-
);
462-
463-
expect(
464-
_getMessageShownInSemanticsDebugger(widgetKey: child, debuggerKey: debugger, tester: tester),
465-
isPlatformAndroid ? 'text' : 'text\ntext',
466-
);
467-
}, variant: TargetPlatformVariant.all());
468-
469441
testWidgets('SemanticsDebugger textfield', (WidgetTester tester) async {
470442
final UniqueKey textField = UniqueKey();
471443
final UniqueKey debugger = UniqueKey();

0 commit comments

Comments
 (0)