Revert "Use semantics label for backbutton and closebutton for Androi… (#111636)
* Roll Flutter Engine from 4096e133ef51 to 6610f3f2a9fb (11 revisions) (#111240)
* Revert Ballistic & Clamping simulation updates (#111201)
* Revert "Update `MaterialBanner` to support Material 3" (#111288)
* Revert "Use semantics label for backbutton and closebutton for Android" (#111305)
Co-authored-by: engine-flutter-autoroll <engine-flutter-autoroll@skia.org>
Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: Casey Hillers <chillers@google.com>
Co-authored-by: Xilai Zhang <xilaizhang@google.com>
diff --git a/packages/flutter/lib/src/material/back_button.dart b/packages/flutter/lib/src/material/back_button.dart
index 3feaba5..4d1f1c8 100644
--- a/packages/flutter/lib/src/material/back_button.dart
+++ b/packages/flutter/lib/src/material/back_button.dart
@@ -27,31 +27,22 @@
/// the current platform (as obtained from the [Theme]).
const BackButtonIcon({ super.key });
- @override
- Widget build(BuildContext context) {
- final String? semanticsLabel;
- final IconData data;
- switch (Theme.of(context).platform) {
+ /// Returns the appropriate "back" icon for the given `platform`.
+ static IconData _getIconData(TargetPlatform platform) {
+ switch (platform) {
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.linux:
case TargetPlatform.windows:
- semanticsLabel = null;
- data = Icons.arrow_back;
- break;
+ return Icons.arrow_back;
case TargetPlatform.iOS:
case TargetPlatform.macOS:
- data = Icons.arrow_back_ios;
- semanticsLabel = null;
- break;
+ return Icons.arrow_back_ios;
}
-
- return Icon(data, semanticLabel: semanticsLabel);
}
+
+ @override
+ Widget build(BuildContext context) => Icon(_getIconData(Theme.of(context).platform));
}
/// A Material Design back button.
@@ -158,22 +149,8 @@
@override
Widget build(BuildContext 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(
- icon: Icon(Icons.close, semanticLabel: semanticsLabel),
+ icon: const Icon(Icons.close),
color: color,
tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
onPressed: () {
diff --git a/packages/flutter/test/material/back_button_test.dart b/packages/flutter/test/material/back_button_test.dart
index 09d9fd1..d4ff9a9 100644
--- a/packages/flutter/test/material/back_button_test.dart
+++ b/packages/flutter/test/material/back_button_test.dart
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -153,21 +152,9 @@
tester.state<NavigatorState>(find.byType(Navigator)).pushNamed('/next');
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(
tooltip: 'Back',
- label: expectedLabel,
isButton: true,
hasEnabledState: true,
isEnabled: true,
@@ -175,51 +162,7 @@
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,
- hasEnabledState: true,
- isEnabled: true,
- hasTapAction: true,
- isFocusable: true,
- ));
- handle.dispose();
- }, variant: TargetPlatformVariant.all());
+ });
testWidgets('CloseButton color', (WidgetTester tester) async {
await tester.pumpWidget(