Skip to content

Commit ddd442f

Browse files
authored
✨ Add full semantics support (#72)
1 parent 28ab6c8 commit ddd442f

File tree

4 files changed

+338
-193
lines changed

4 files changed

+338
-193
lines changed

lib/src/constants/constants.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ export 'screens.dart';
1212
class Constants {
1313
const Constants._();
1414

15-
static CameraPickerTextDelegate textDelegate =
16-
DefaultCameraPickerTextDelegate();
15+
static CameraPickerTextDelegate textDelegate = CameraPickerTextDelegate();
1716
}

lib/src/delegates/camera_picker_text_delegate.dart

Lines changed: 97 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,105 @@
22
/// [Author] Alex (https://github.com/AlexV525)
33
/// [Date] 2020/7/16 11:07
44
///
5+
import 'package:camera/camera.dart' show CameraLensDirection, FlashMode;
56

6-
/// Text delegate that controls text in widgets.
7-
/// 控制部件中的文字实现
8-
abstract class CameraPickerTextDelegate {
7+
/// Text delegate that controls text in widgets, implemented with Chinese.
8+
/// 控制部件中的文字实现,中文。
9+
class CameraPickerTextDelegate {
910
/// Confirm string for the confirm button.
1011
/// 确认按钮的字段
11-
String get confirm;
12+
String get confirm => '确认';
1213

1314
/// Tips string above the shooting button before shooting.
1415
/// 拍摄前确认按钮上方的提示文字
15-
String get shootingTips;
16+
String get shootingTips => '轻触拍照';
1617

1718
/// Load failed string for item.
1819
/// 资源加载失败时的字段
19-
String get loadFailed;
20-
}
20+
String get loadFailed => '加载失败';
2121

22-
/// Default text delegate implements with Chinese.
23-
/// 中文文字实现
24-
class DefaultCameraPickerTextDelegate extends CameraPickerTextDelegate {
25-
@override
26-
String get confirm => '确认';
22+
/// Semantics fields.
23+
///
24+
/// Fields below are only for semantics usage. For customizable these fields,
25+
/// head over to [EnglishCameraPickerTextDelegate] for fields understanding.
26+
String get sActionManuallyFocusHint => '手动聚焦';
2727

28-
@override
29-
String get shootingTips => '轻触拍照';
28+
String get sActionPreviewHint => '预览';
3029

31-
@override
32-
String get loadFailed => '加载失败';
30+
String get sActionRecordHint => '录像';
31+
32+
String get sActionShootHint => '拍照';
33+
34+
String get sActionShootingButtonTooltip => '拍照按钮';
35+
36+
String get sActionStopRecordingHint => '停止录像';
37+
38+
String get sActionSwitchCameraTooltip => '切换摄像头';
39+
40+
String get sActionToggleFlashModeTooltip => '切换闪光模式';
41+
42+
String sCameraLensDirectionLabel(CameraLensDirection value) {
43+
final String _direction;
44+
switch (value) {
45+
case CameraLensDirection.front:
46+
_direction = '前置';
47+
break;
48+
case CameraLensDirection.back:
49+
_direction = '后置';
50+
break;
51+
case CameraLensDirection.external:
52+
_direction = '外置';
53+
break;
54+
}
55+
return '当前摄像头: $_direction';
56+
}
57+
58+
String sFlashModeLabel(FlashMode mode) {
59+
final String _modeString;
60+
switch (mode) {
61+
case FlashMode.off:
62+
_modeString = '关闭';
63+
break;
64+
case FlashMode.auto:
65+
_modeString = '自动';
66+
break;
67+
case FlashMode.always:
68+
_modeString = '拍照时闪光';
69+
break;
70+
case FlashMode.torch:
71+
_modeString = '始终闪光';
72+
break;
73+
}
74+
return '当前闪光模式: $_modeString';
75+
}
3376
}
3477

3578
/// Default text delegate including recording implements with Chinese.
3679
/// 中文文字实现(包括摄像)
37-
class DefaultCameraPickerTextDelegateWithRecording
38-
extends DefaultCameraPickerTextDelegate {
80+
class CameraPickerTextDelegateWithRecording extends CameraPickerTextDelegate {
3981
@override
4082
String get shootingTips => '轻触拍照,长按摄像';
4183
}
4284

4385
/// Default text delegate including only recording implements with Chinese.
4486
/// 中文文字实现(仅摄像)
45-
class DefaultCameraPickerTextDelegateWithOnlyRecording
46-
extends DefaultCameraPickerTextDelegate {
87+
class CameraPickerTextDelegateWithOnlyRecording
88+
extends CameraPickerTextDelegate {
4789
@override
4890
String get shootingTips => '长按摄像';
4991
}
5092

5193
/// Default text delegate including tap recording implements with Chinese.
5294
/// 中文文字实现(仅轻触摄像)
53-
class DefaultCameraPickerTextDelegateWithTapRecording
54-
extends DefaultCameraPickerTextDelegate {
95+
class CameraPickerTextDelegateWithTapRecording
96+
extends CameraPickerTextDelegate {
5597
@override
5698
String get shootingTips => '轻触摄像';
5799
}
58100

59101
/// Default text delegate implements with English.
60102
/// 英文文字实现
61-
class EnglishCameraPickerTextDelegate implements CameraPickerTextDelegate {
103+
class EnglishCameraPickerTextDelegate extends CameraPickerTextDelegate {
62104
@override
63105
String get confirm => 'Confirm';
64106

@@ -67,6 +109,38 @@ class EnglishCameraPickerTextDelegate implements CameraPickerTextDelegate {
67109

68110
@override
69111
String get loadFailed => 'Load failed';
112+
113+
@override
114+
String get sActionManuallyFocusHint => 'manually focus';
115+
116+
@override
117+
String get sActionPreviewHint => 'preview';
118+
119+
@override
120+
String get sActionRecordHint => 'record';
121+
122+
@override
123+
String get sActionShootHint => 'take picture';
124+
125+
@override
126+
String get sActionShootingButtonTooltip => 'shooting button';
127+
128+
@override
129+
String get sActionStopRecordingHint => 'stop recording';
130+
131+
@override
132+
String get sActionSwitchCameraTooltip => 'switch camera';
133+
134+
@override
135+
String get sActionToggleFlashModeTooltip => 'toggle flashlight';
136+
137+
@override
138+
String sCameraLensDirectionLabel(CameraLensDirection value) =>
139+
'Current camera lens direction: ${value.name}';
140+
141+
@override
142+
String sFlashModeLabel(FlashMode mode) =>
143+
'Current flashlight mode: ${mode.name}';
70144
}
71145

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

0 commit comments

Comments
 (0)