Skip to content

Commit d563ffe

Browse files
committed
♿️ Improve semantics expressions
1 parent 3ee6509 commit d563ffe

File tree

2 files changed

+48
-33
lines changed

2 files changed

+48
-33
lines changed

lib/src/delegates/camera_picker_text_delegate.dart

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CameraPickerTextDelegate {
2222
/// Semantics fields.
2323
///
2424
/// Fields below are only for semantics usage. For customizable these fields,
25-
/// head over to [EnglishCameraPickerTextDelegate] for fields understanding.
25+
/// head over to [EnglishCameraPickerTextDelegate] for better understanding.
2626
String get sActionManuallyFocusHint => '手动聚焦';
2727

2828
String get sActionPreviewHint => '预览';
@@ -35,24 +35,22 @@ class CameraPickerTextDelegate {
3535

3636
String get sActionStopRecordingHint => '停止录像';
3737

38-
String get sActionSwitchCameraTooltip => '切换摄像头';
39-
40-
String get sActionToggleFlashModeTooltip => '切换闪光模式';
41-
4238
String sCameraLensDirectionLabel(CameraLensDirection value) {
43-
final String _direction;
4439
switch (value) {
4540
case CameraLensDirection.front:
46-
_direction = '前置';
47-
break;
41+
return '前置';
4842
case CameraLensDirection.back:
49-
_direction = '后置';
50-
break;
43+
return '后置';
5144
case CameraLensDirection.external:
52-
_direction = '外置';
53-
break;
45+
return '外置';
46+
}
47+
}
48+
49+
String? sCameraPreviewLabel(CameraLensDirection? value) {
50+
if (value == null) {
51+
return null;
5452
}
55-
return '当前摄像头: $_direction';
53+
return '${sCameraLensDirectionLabel(value)}画面预览';
5654
}
5755

5856
String sFlashModeLabel(FlashMode mode) {
@@ -71,7 +69,11 @@ class CameraPickerTextDelegate {
7169
_modeString = '始终闪光';
7270
break;
7371
}
74-
return '当前闪光模式: $_modeString';
72+
return '闪光模式: $_modeString';
73+
}
74+
75+
String sSwitchCameraLensDirectionLabel(CameraLensDirection value) {
76+
return '切换至${sCameraLensDirectionLabel(value)}摄像头';
7577
}
7678
}
7779

@@ -129,18 +131,22 @@ class EnglishCameraPickerTextDelegate extends CameraPickerTextDelegate {
129131
String get sActionStopRecordingHint => 'stop recording';
130132

131133
@override
132-
String get sActionSwitchCameraTooltip => 'switch camera';
134+
String sCameraLensDirectionLabel(CameraLensDirection value) => value.name;
133135

134136
@override
135-
String get sActionToggleFlashModeTooltip => 'toggle flashlight';
137+
String? sCameraPreviewLabel(CameraLensDirection? value) {
138+
if (value == null) {
139+
return null;
140+
}
141+
return '${sCameraLensDirectionLabel(value)} camera preview';
142+
}
136143

137144
@override
138-
String sCameraLensDirectionLabel(CameraLensDirection value) =>
139-
'Current camera lens direction: ${value.name}';
145+
String sFlashModeLabel(FlashMode mode) => 'Flash mode: ${mode.name}';
140146

141147
@override
142-
String sFlashModeLabel(FlashMode mode) =>
143-
'Current flashlight mode: ${mode.name}';
148+
String sSwitchCameraLensDirectionLabel(CameraLensDirection value) =>
149+
'Switch to the ${sCameraLensDirectionLabel(value)} camera';
144150
}
145151

146152
/// Default text delegate including recording implements with English.

lib/src/widgets/camera_picker.dart

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,15 @@ class CameraPickerState extends State<CameraPicker>
625625
initCameras(currentCamera);
626626
}
627627

628+
/// Obtain the next camera description for semantics.
629+
CameraDescription get _nextCameraDescription {
630+
final int nextIndex = currentCameraIndex + 1;
631+
if (nextIndex == cameras.length) {
632+
return cameras[0];
633+
}
634+
return cameras[nextIndex];
635+
}
636+
628637
/// The method to switch between flash modes.
629638
/// 切换闪光灯模式的方法
630639
Future<void> switchFlashesMode() async {
@@ -1002,8 +1011,7 @@ class CameraPickerState extends State<CameraPicker>
10021011
padding: const EdgeInsets.symmetric(horizontal: 12.0),
10031012
child: Row(
10041013
children: <Widget>[
1005-
if (cameras.length > 1)
1006-
switchCamerasButton(controller.description.lensDirection),
1014+
if (cameras.length > 1) switchCamerasButton,
10071015
const Spacer(),
10081016
switchFlashesButton(v),
10091017
],
@@ -1015,10 +1023,11 @@ class CameraPickerState extends State<CameraPicker>
10151023

10161024
/// The button to switch between cameras.
10171025
/// 切换相机的按钮
1018-
Widget switchCamerasButton(CameraLensDirection value) {
1026+
Widget get switchCamerasButton {
10191027
return IconButton(
1020-
tooltip: '${_textDelegate.sActionSwitchCameraTooltip}, '
1021-
'${_textDelegate.sCameraLensDirectionLabel(value)}',
1028+
tooltip: _textDelegate.sSwitchCameraLensDirectionLabel(
1029+
_nextCameraDescription.lensDirection,
1030+
),
10221031
onPressed: switchCameras,
10231032
icon: Icon(
10241033
Platform.isIOS
@@ -1045,13 +1054,10 @@ class CameraPickerState extends State<CameraPicker>
10451054
icon = Icons.flash_on;
10461055
break;
10471056
}
1048-
return Semantics(
1049-
label: '${_textDelegate.sActionToggleFlashModeTooltip}, '
1050-
'${_textDelegate.sFlashModeLabel(value.flashMode)}',
1051-
child: IconButton(
1052-
onPressed: switchFlashesMode,
1053-
icon: Icon(icon, size: 24),
1054-
),
1057+
return IconButton(
1058+
onPressed: switchFlashesMode,
1059+
tooltip: _textDelegate.sFlashModeLabel(value.flashMode),
1060+
icon: Icon(icon, size: 24),
10551061
);
10561062
}
10571063

@@ -1374,7 +1380,10 @@ class CameraPickerState extends State<CameraPicker>
13741380

13751381
return Positioned.fill(
13761382
child: Semantics(
1377-
label: _textDelegate.sActionManuallyFocusHint,
1383+
label: _textDelegate.sCameraPreviewLabel(
1384+
_controller?.description.lensDirection,
1385+
),
1386+
image: true,
13781387
onTap: () => _focus(
13791388
TapUpDetails(
13801389
kind: PointerDeviceKind.touch,

0 commit comments

Comments
 (0)