Unverified Commit 20a78ed6 authored by Xilai Zhang's avatar Xilai Zhang Committed by GitHub

Revert "Use semantics label for backbutton and closebutton for Android" (#111305)

parent c6d44e25
...@@ -27,31 +27,22 @@ class BackButtonIcon extends StatelessWidget { ...@@ -27,31 +27,22 @@ class BackButtonIcon extends StatelessWidget {
/// the current platform (as obtained from the [Theme]). /// the current platform (as obtained from the [Theme]).
const BackButtonIcon({ super.key }); const BackButtonIcon({ super.key });
@override /// Returns the appropriate "back" icon for the given `platform`.
Widget build(BuildContext context) { static IconData _getIconData(TargetPlatform platform) {
final String? semanticsLabel; switch (platform) {
final IconData data;
switch (Theme.of(context).platform) {
case TargetPlatform.android: case TargetPlatform.android:
// Android uses semantics label to annotate the back button.
semanticsLabel = MaterialLocalizations.of(context).backButtonTooltip;
data = Icons.arrow_back;
break;
case TargetPlatform.fuchsia: case TargetPlatform.fuchsia:
case TargetPlatform.linux: case TargetPlatform.linux:
case TargetPlatform.windows: case TargetPlatform.windows:
semanticsLabel = null; return Icons.arrow_back;
data = Icons.arrow_back;
break;
case TargetPlatform.iOS: case TargetPlatform.iOS:
case TargetPlatform.macOS: case TargetPlatform.macOS:
data = Icons.arrow_back_ios; return Icons.arrow_back_ios;
semanticsLabel = null;
break;
} }
return Icon(data, semanticLabel: semanticsLabel);
} }
@override
Widget build(BuildContext context) => Icon(_getIconData(Theme.of(context).platform));
} }
/// A Material Design back button. /// A Material Design back button.
...@@ -158,22 +149,8 @@ class CloseButton extends StatelessWidget { ...@@ -158,22 +149,8 @@ class CloseButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(debugCheckHasMaterialLocalizations(context)); assert(debugCheckHasMaterialLocalizations(context));
final String? semanticsLabel;
switch (Theme.of(context).platform) {
case TargetPlatform.android:
// Android uses semantics label to annotate the close button.
semanticsLabel = MaterialLocalizations.of(context).closeButtonTooltip;
break;
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.windows:
case TargetPlatform.iOS:
case TargetPlatform.macOS:
semanticsLabel = null;
break;
}
return IconButton( return IconButton(
icon: Icon(Icons.close, semanticLabel: semanticsLabel), icon: const Icon(Icons.close),
color: color, color: color,
tooltip: MaterialLocalizations.of(context).closeButtonTooltip, tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
onPressed: () { onPressed: () {
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -153,65 +152,9 @@ void main() { ...@@ -153,65 +152,9 @@ void main() {
tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next'); tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final String? expectedLabel;
switch(defaultTargetPlatform) {
case TargetPlatform.android:
expectedLabel = 'Back';
break;
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
expectedLabel = null;
}
expect(tester.getSemantics(find.byType(BackButton)), matchesSemantics( expect(tester.getSemantics(find.byType(BackButton)), matchesSemantics(
tooltip: 'Back', tooltip: 'Back',
label: expectedLabel,
isButton: true,
hasEnabledState: true,
isEnabled: true,
hasTapAction: true,
isFocusable: true,
));
handle.dispose();
}, variant: TargetPlatformVariant.all());
testWidgets('CloseButton semantics', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
home: const Material(child: Text('Home')),
routes: <String, WidgetBuilder>{
'/next': (BuildContext context) {
return const Material(
child: Center(
child: CloseButton(),
),
);
},
},
),
);
tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');
await tester.pumpAndSettle();
final String? expectedLabel;
switch(defaultTargetPlatform) {
case TargetPlatform.android:
expectedLabel = 'Close';
break;
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
expectedLabel = null;
}
expect(tester.getSemantics(find.byType(CloseButton)), matchesSemantics(
tooltip: 'Close',
label: expectedLabel,
isButton: true, isButton: true,
hasEnabledState: true, hasEnabledState: true,
isEnabled: true, isEnabled: true,
...@@ -219,7 +162,7 @@ void main() { ...@@ -219,7 +162,7 @@ void main() {
isFocusable: true, isFocusable: true,
)); ));
handle.dispose(); handle.dispose();
}, variant: TargetPlatformVariant.all()); });
testWidgets('CloseButton color', (WidgetTester tester) async { testWidgets('CloseButton color', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment