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' ;
65import 'package:flutter/widgets.dart' ;
76
87import '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: () {
0 commit comments