Skip to content

Commit fa258ea

Browse files
authored
♿️ Fix semantics issues (#672)
Update according to the feedback from @luomo-pro
1 parent b03511c commit fa258ea

File tree

4 files changed

+42
-35
lines changed

4 files changed

+42
-35
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ that can be found in the LICENSE file. -->
99
1010
## Unreleased
1111

12-
*None.*
12+
### Fixes
13+
14+
- Fixes semantics issues.
1315

1416
## 9.4.2
1517

@@ -146,7 +148,7 @@ that can be found in the LICENSE file. -->
146148

147149
### Improvements
148150

149-
- Improve code formatting.
151+
- Improve code formatting.
150152

151153
## 9.0.0
152154

@@ -900,7 +902,7 @@ To know more about breaking changes, see [Migration Guide][].
900902

901903
## 1.4.1
902904

903-
- Remove the loading indicator for the image widget.
905+
- Remove the loading indicator for the image widget.
904906
- Refactor the video page's initialization for ratio update.
905907
- Using constants to store text delegate.
906908
- Add error catching for main methods.

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,11 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
620620
tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
621621
icon: Icon(
622622
Icons.close,
623-
semanticLabel: MaterialLocalizations.of(context).closeButtonTooltip,
623+
semanticLabel: switch (Theme.of(context).platform) {
624+
TargetPlatform.android =>
625+
MaterialLocalizations.of(context).closeButtonTooltip,
626+
_ => null,
627+
},
624628
),
625629
),
626630
);
@@ -1488,28 +1492,24 @@ class DefaultAssetPickerBuilderDelegate
14881492
asset.toString(),
14891493
);
14901494
final int selectedIndex = p.selectedAssets.indexOf(asset) + 1;
1491-
String hint = '';
1492-
if (asset.type == AssetType.audio ||
1493-
asset.type == AssetType.video) {
1494-
hint += '${semanticsTextDelegate.sNameDurationLabel}: ';
1495-
hint += semanticsTextDelegate.durationIndicatorBuilder(
1496-
asset.videoDuration,
1497-
);
1498-
}
1499-
if (asset.title?.isNotEmpty ?? false) {
1500-
hint += ', ${asset.title}';
1501-
}
1495+
final labels = <String>[
1496+
'${semanticsTextDelegate.semanticTypeLabel(asset.type)}'
1497+
'${semanticIndex(index)}',
1498+
asset.createDateTime.toString().replaceAll('.000', ''),
1499+
if (asset.type == AssetType.audio ||
1500+
asset.type == AssetType.video)
1501+
'${semanticsTextDelegate.sNameDurationLabel}: '
1502+
'${semanticsTextDelegate.durationIndicatorBuilder(asset.videoDuration)}',
1503+
if (asset.title case final title? when title.isNotEmpty) title,
1504+
];
15021505
return Semantics(
15031506
key: ValueKey('${asset.id}-semantics'),
15041507
button: false,
15051508
enabled: !isBanned,
15061509
excludeSemantics: true,
15071510
focusable: !isSwitchingPath,
1508-
label: '${semanticsTextDelegate.semanticTypeLabel(asset.type)}'
1509-
'${semanticIndex(index)}, '
1510-
'${asset.createDateTime.toString().replaceAll('.000', '')}',
1511+
label: labels.join(', '),
15111512
hidden: isSwitchingPath,
1512-
hint: hint,
15131513
image: asset.type == AssetType.image ||
15141514
asset.type == AssetType.video,
15151515
onTap: () {

lib/src/delegates/asset_picker_viewer_builder_delegate.dart

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -460,20 +460,18 @@ class DefaultAssetPickerViewerBuilderDelegate
460460
final bool isSelected =
461461
(p?.currentlySelectedAssets ?? selectedAssets)?.contains(asset) ??
462462
false;
463-
String hint = '';
464-
if (asset.type == AssetType.audio || asset.type == AssetType.video) {
465-
hint += '${semanticsTextDelegate.sNameDurationLabel}: ';
466-
hint += textDelegate.durationIndicatorBuilder(asset.videoDuration);
467-
}
468-
if (asset.title?.isNotEmpty ?? false) {
469-
hint += ', ${asset.title}';
470-
}
463+
final labels = <String>[
464+
'${semanticsTextDelegate.semanticTypeLabel(asset.type)}'
465+
'${index + 1}',
466+
asset.createDateTime.toString().replaceAll('.000', ''),
467+
if (asset.type == AssetType.audio || asset.type == AssetType.video)
468+
'${semanticsTextDelegate.sNameDurationLabel}: '
469+
'${semanticsTextDelegate.durationIndicatorBuilder(asset.videoDuration)}',
470+
if (asset.title case final title? when title.isNotEmpty) title,
471+
];
471472
return Semantics(
472-
label: '${semanticsTextDelegate.semanticTypeLabel(asset.type)}'
473-
'${index + 1}, '
474-
'${asset.createDateTime.toString().replaceAll('.000', '')}',
473+
label: labels.join(', '),
475474
selected: isSelected,
476-
hint: hint,
477475
image:
478476
asset.type == AssetType.image || asset.type == AssetType.video,
479477
child: w,
@@ -737,7 +735,11 @@ class DefaultAssetPickerViewerBuilderDelegate
737735
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
738736
icon: Icon(
739737
Icons.arrow_back_ios_new,
740-
semanticLabel: MaterialLocalizations.of(context).backButtonTooltip,
738+
semanticLabel: switch (Theme.of(context).platform) {
739+
TargetPlatform.android =>
740+
MaterialLocalizations.of(context).backButtonTooltip,
741+
_ => null,
742+
},
741743
),
742744
),
743745
),

lib/src/widget/builder/audio_page_builder.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,12 @@ class _AudioPageBuilderState extends State<AudioPageBuilder> {
141141
/// Title widget.
142142
/// 标题组件
143143
Widget get titleWidget {
144-
return ScaleText(
145-
widget.asset.title ?? '',
146-
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.normal),
144+
// Excluding audio title from semantics since the label already includes.
145+
return ExcludeSemantics(
146+
child: ScaleText(
147+
widget.asset.title ?? '',
148+
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.normal),
149+
),
147150
);
148151
}
149152

0 commit comments

Comments
 (0)