From 049e4def274132fe2e902a7c7d6d36e5e776a63c Mon Sep 17 00:00:00 2001 From: Serhii Date: Wed, 13 Dec 2023 17:27:30 +0200 Subject: [PATCH] fix accessibility issues (#1224) --- .../settings/display_settings_page.dart | 2 +- .../widgets/settings_theme_choice.dart | 100 +++++++++--------- lib/src/widgets/standard_switch.dart | 40 +++---- 3 files changed, 75 insertions(+), 67 deletions(-) diff --git a/lib/src/screens/settings/display_settings_page.dart b/lib/src/screens/settings/display_settings_page.dart index 505573f8..ba59df3a 100644 --- a/lib/src/screens/settings/display_settings_page.dart +++ b/lib/src/screens/settings/display_settings_page.dart @@ -76,7 +76,7 @@ class DisplaySettingsPage extends BasePage { }, ), if (responsiveLayoutUtil.shouldRenderMobileUI && DeviceInfo.instance.isMobile) - SettingsThemeChoicesCell(_displaySettingsViewModel), + Semantics(label: S.current.color_theme, child: SettingsThemeChoicesCell(_displaySettingsViewModel)), ], ), ); diff --git a/lib/src/screens/settings/widgets/settings_theme_choice.dart b/lib/src/screens/settings/widgets/settings_theme_choice.dart index ffb9d7e7..abe9a4ea 100644 --- a/lib/src/screens/settings/widgets/settings_theme_choice.dart +++ b/lib/src/screens/settings/widgets/settings_theme_choice.dart @@ -54,57 +54,61 @@ class SettingsThemeChoicesCell extends StatelessWidget { return Padding( padding: EdgeInsets.all(5), - child: GestureDetector( - onTap: () { - _displaySettingsViewModel.setTheme(e); - }, - child: Container( - padding: EdgeInsets.all(5), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(cellRadius), - border: isSelected - ? Border.all( - color: Theme.of(context).primaryColor) - : null, - color: Theme.of(context) - .extension()! - .secondaryTextColor - .withOpacity( - currentTheme.brightness == Brightness.light - ? 0.1 - : 0.3), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - padding: EdgeInsets.symmetric( - horizontal: cellWidth, vertical: cellHeight), - decoration: BoxDecoration( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(cellRadius), - bottomLeft: Radius.circular(cellRadius)), - color: e.themeData.primaryColor, + child: Semantics( + label: e.toString(), + selected: isSelected, + child: GestureDetector( + onTap: () { + _displaySettingsViewModel.setTheme(e); + }, + child: Container( + padding: EdgeInsets.all(5), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(cellRadius), + border: isSelected + ? Border.all( + color: Theme.of(context).primaryColor) + : null, + color: Theme.of(context) + .extension()! + .secondaryTextColor + .withOpacity( + currentTheme.brightness == Brightness.light + ? 0.1 + : 0.3), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + padding: EdgeInsets.symmetric( + horizontal: cellWidth, vertical: cellHeight), + decoration: BoxDecoration( + borderRadius: BorderRadius.only( + topLeft: Radius.circular(cellRadius), + bottomLeft: Radius.circular(cellRadius)), + color: e.themeData.primaryColor, + ), ), - ), - Container( - padding: EdgeInsets.symmetric( - horizontal: cellWidth, vertical: cellHeight), - decoration: BoxDecoration( - color: e.themeData.colorScheme.background, + Container( + padding: EdgeInsets.symmetric( + horizontal: cellWidth, vertical: cellHeight), + decoration: BoxDecoration( + color: e.themeData.colorScheme.background, + ), ), - ), - Container( - padding: EdgeInsets.symmetric( - horizontal: cellWidth, vertical: cellHeight), - decoration: BoxDecoration( - borderRadius: BorderRadius.only( - topRight: Radius.circular(cellRadius), - bottomRight: Radius.circular(cellRadius)), - color: e.themeData.cardColor, + Container( + padding: EdgeInsets.symmetric( + horizontal: cellWidth, vertical: cellHeight), + decoration: BoxDecoration( + borderRadius: BorderRadius.only( + topRight: Radius.circular(cellRadius), + bottomRight: Radius.circular(cellRadius)), + color: e.themeData.cardColor, + ), ), - ), - ], + ], + ), ), ), ), diff --git a/lib/src/widgets/standard_switch.dart b/lib/src/widgets/standard_switch.dart index 064faea4..b80d487f 100644 --- a/lib/src/widgets/standard_switch.dart +++ b/lib/src/widgets/standard_switch.dart @@ -14,25 +14,29 @@ class StandardSwitch extends StatefulWidget { class StandardSwitchState extends State { @override Widget build(BuildContext context) { - return GestureDetector( - onTap: widget.onTaped, - child: AnimatedContainer( - padding: EdgeInsets.only(left: 2.0, right: 2.0), - alignment: widget.value ? Alignment.centerRight : Alignment.centerLeft, - duration: Duration(milliseconds: 250), - width: 50, - height: 28, - decoration: BoxDecoration( - color: widget.value - ? Theme.of(context).primaryColor - : Theme.of(context).disabledColor, - borderRadius: BorderRadius.all(Radius.circular(14.0))), - child: Container( - width: 24.0, - height: 24.0, + + return Semantics( + toggled: widget.value, + child: GestureDetector( + onTap: widget.onTaped, + child: AnimatedContainer( + padding: EdgeInsets.only(left: 2.0, right: 2.0), + alignment: widget.value ? Alignment.centerRight : Alignment.centerLeft, + duration: Duration(milliseconds: 250), + width: 50, + height: 28, decoration: BoxDecoration( - color: Colors.white, - shape: BoxShape.circle), + color: widget.value + ? Theme.of(context).primaryColor + : Theme.of(context).disabledColor, + borderRadius: BorderRadius.all(Radius.circular(14.0))), + child: Container( + width: 24.0, + height: 24.0, + decoration: BoxDecoration( + color: Colors.white, + shape: BoxShape.circle), + ), ), ), );