Skip to content

Commit efc8eeb

Browse files
committed
✨ Add camera picker text delegate.
1 parent 4edb4ee commit efc8eeb

File tree

4 files changed

+112
-4
lines changed

4 files changed

+112
-4
lines changed

lib/src/constants/constants.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
/// [Author] Alex (https://github.com/AlexV525)
33
/// [Date] 2020/7/15 02:06
44
///
5+
import 'package:wechat_camera_picker/wechat_camera_picker.dart';
6+
57
export 'package:flutter_common_exports/flutter_common_exports.dart';
8+
export 'package:photo_manager/photo_manager.dart';
69

10+
export '../delegates/camera_picker_text_delegate.dart';
711
export 'colors.dart';
12+
13+
class Constants {
14+
const Constants._();
15+
16+
static CameraPickerTextDelegate textDelegate =
17+
DefaultCameraPickerTextDelegate();
18+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
///
2+
/// [Author] Alex (https://github.com/AlexV525)
3+
/// [Date] 2020/7/16 11:07
4+
///
5+
6+
/// Text delegate that controls text in widgets.
7+
/// 控制部件中的文字实现
8+
abstract class CameraPickerTextDelegate {
9+
/// Confirm string for the confirm button.
10+
/// 确认按钮的字段
11+
String confirm;
12+
13+
/// Tips string above the shooting button before shooting.
14+
/// 拍摄前确认按钮上方的提示文字
15+
String shootingTips;
16+
}
17+
18+
/// Default text delegate implements with Chinese.
19+
/// 中文文字实现
20+
class DefaultCameraPickerTextDelegate implements CameraPickerTextDelegate {
21+
factory DefaultCameraPickerTextDelegate() => _instance;
22+
23+
DefaultCameraPickerTextDelegate._internal();
24+
25+
static final DefaultCameraPickerTextDelegate _instance =
26+
DefaultCameraPickerTextDelegate._internal();
27+
28+
@override
29+
String confirm = '确认';
30+
31+
@override
32+
String shootingTips = '轻触拍照';
33+
}
34+
35+
/// Default text delegate implements with Chinese.
36+
/// 中文文字实现
37+
class DefaultCameraPickerTextDelegateWithRecording
38+
implements CameraPickerTextDelegate {
39+
factory DefaultCameraPickerTextDelegateWithRecording() => _instance;
40+
41+
DefaultCameraPickerTextDelegateWithRecording._internal();
42+
43+
static final DefaultCameraPickerTextDelegateWithRecording _instance =
44+
DefaultCameraPickerTextDelegateWithRecording._internal();
45+
46+
@override
47+
String confirm = '确认';
48+
49+
@override
50+
String shootingTips = '轻触拍照,长按摄像';
51+
}
52+
53+
/// Default text delegate implements with English.
54+
/// 英文文字实现
55+
class EnglishCameraPickerTextDelegate implements CameraPickerTextDelegate {
56+
factory EnglishCameraPickerTextDelegate() => _instance;
57+
58+
EnglishCameraPickerTextDelegate._internal();
59+
60+
static final EnglishCameraPickerTextDelegate _instance =
61+
EnglishCameraPickerTextDelegate._internal();
62+
63+
@override
64+
String confirm = 'Confirm';
65+
66+
@override
67+
String shootingTips = 'Tap to take photo.';
68+
}

lib/src/widget/camera_picker.dart

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ import 'builder/slide_page_transition_builder.dart';
2626
/// 该选择器可以通过拍照创建 [AssetEntity] ,但由于过程中有的步骤随时会出现问题,
2727
/// 使用时有较高的概率会遇到失败。
2828
class CameraPicker extends StatefulWidget {
29-
const CameraPicker({
29+
CameraPicker({
3030
Key key,
3131
this.shouldKeptInLocal = false,
3232
this.isAllowRecording = false,
3333
this.theme,
34-
}) : super(key: key);
34+
CameraPickerTextDelegate textDelegate,
35+
}) : super(key: key) {
36+
Constants.textDelegate = textDelegate ?? DefaultCameraPickerTextDelegate();
37+
}
3538

3639
/// Whether the taken file should be kept in local.
3740
/// 拍照的文件是否应该保存在本地
@@ -47,7 +50,10 @@ class CameraPicker extends StatefulWidget {
4750
/// 通过相机创建 [AssetEntity] 的静态方法
4851
static Future<AssetEntity> pickFromCamera(
4952
BuildContext context, {
50-
bool shouldKeptInLocal = true,
53+
bool shouldKeptInLocal = false,
54+
bool isAllowRecording = false,
55+
ThemeData theme,
56+
CameraPickerTextDelegate textDelegate,
5157
}) async {
5258
final AssetEntity result = await Navigator.of(
5359
context,
@@ -56,6 +62,9 @@ class CameraPicker extends StatefulWidget {
5662
SlidePageTransitionBuilder<AssetEntity>(
5763
builder: CameraPicker(
5864
shouldKeptInLocal: shouldKeptInLocal,
65+
isAllowRecording: isAllowRecording,
66+
theme: theme,
67+
textDelegate: textDelegate,
5968
),
6069
transitionCurve: Curves.easeIn,
6170
transitionDuration: const Duration(milliseconds: 300),
@@ -353,6 +362,24 @@ class _CameraPickerState extends State<CameraPicker> {
353362
);
354363
}
355364

365+
/// Text widget for shooting tips.
366+
/// 拍摄的提示文字
367+
Widget get tipsTextWidget {
368+
return AnimatedOpacity(
369+
duration: recordDetectDuration,
370+
opacity: isRecording ? 0.0 : 1.0,
371+
child: Padding(
372+
padding: const EdgeInsets.symmetric(
373+
vertical: 20.0,
374+
),
375+
child: Text(
376+
Constants.textDelegate.shootingTips,
377+
style: const TextStyle(fontSize: 15.0),
378+
),
379+
),
380+
);
381+
}
382+
356383
/// Shooting action section widget.
357384
/// 拍照操作区
358385
///
@@ -588,9 +615,10 @@ class _CameraPickerState extends State<CameraPicker> {
588615
child: Padding(
589616
padding: const EdgeInsets.symmetric(vertical: 20.0),
590617
child: Column(
591-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
592618
children: <Widget>[
593619
settingsAction,
620+
const Spacer(),
621+
tipsTextWidget,
594622
shootingActions,
595623
],
596624
),

lib/wechat_camera_picker.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ library wechat_camera_picker;
22

33
export 'package:photo_manager/photo_manager.dart';
44

5+
export 'src/delegates/camera_picker_text_delegate.dart';
56
export 'src/widget/camera_picker.dart';
67
export 'src/widget/temp_picker.dart';

0 commit comments

Comments
 (0)