Skip to content

Commit 53869c9

Browse files
committed
♻️ Reconstruct folders
1 parent 18fb413 commit 53869c9

14 files changed

+100
-61
lines changed

lib/src/constants/constants.dart

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
/// [Author] Alex (https://github.com/AlexV525)
33
/// [Date] 2020/7/15 02:06
44
///
5-
import 'dart:async';
6-
import 'dart:developer';
7-
8-
import 'package:flutter/foundation.dart';
9-
import 'package:flutter/widgets.dart';
10-
import 'package:wechat_camera_picker/wechat_camera_picker.dart';
5+
import '../delegates/camera_picker_text_delegate.dart';
116

127
export 'package:photo_manager/photo_manager.dart';
138

149
export '../delegates/camera_picker_text_delegate.dart';
15-
export 'colors.dart';
1610
export 'screens.dart';
1711

1812
class Constants {
@@ -21,25 +15,3 @@ class Constants {
2115
static CameraPickerTextDelegate textDelegate =
2216
DefaultCameraPickerTextDelegate();
2317
}
24-
25-
/// Log only in debug mode.
26-
/// 只在调试模式打印
27-
void realDebugPrint(dynamic message) {
28-
if (!kReleaseMode) {
29-
log('$message', name: 'CameraPicker - LOG');
30-
}
31-
}
32-
33-
int get currentTimeStamp => DateTime.now().millisecondsSinceEpoch;
34-
35-
const BorderRadius maxBorderRadius = BorderRadius.all(Radius.circular(999999));
36-
37-
extension SafeSetStateExtension on State {
38-
FutureOr<void> safeSetState(FutureOr<dynamic> Function() fn) async {
39-
await fn();
40-
if (mounted) {
41-
// ignore: invalid_use_of_protected_member
42-
setState(() {});
43-
}
44-
}
45-
}

lib/src/constants/screens.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
///
55
import 'dart:ui' as ui;
66

7-
import 'package:flutter/material.dart';
87
import 'package:flutter/services.dart';
8+
import 'package:flutter/widgets.dart';
99

1010
/// Screens utils with multiple properties access.
1111
/// 获取屏幕各项属性的工具类
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
///
22
/// [Author] Alex (https://github.com/AlexV525)
3-
/// [Date] 2020/7/15 02:05
3+
/// [Date] 2021/9/30 17:00
44
///
55
import 'package:flutter/painting.dart';
66

77
class C {
88
static const Color themeColor = Color(0xff00bc56); // WeChat
99
}
10+
11+
const BorderRadius maxBorderRadius = BorderRadius.all(Radius.circular(999999));

lib/src/internals/enums.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
///
2+
/// [Author] Alex (https://github.com/AlexV525)
3+
/// [Date] 2021/9/30 17:06
4+
///
5+
6+
/// Two types for the viewer: image and video.
7+
/// 两种预览类型:图片和视频
8+
enum CameraPickerViewType { image, video }

lib/src/internals/extensions.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
///
3+
/// [Author] Alex (https://github.com/AlexV525)
4+
/// [Date] 2021/9/30 17:02
5+
///
6+
import 'dart:async';
7+
8+
import 'package:flutter/widgets.dart';
9+
10+
extension SafeSetStateExtension on State {
11+
FutureOr<void> safeSetState(FutureOr<dynamic> Function() fn) async {
12+
await fn();
13+
if (mounted) {
14+
// ignore: invalid_use_of_protected_member
15+
setState(() {});
16+
}
17+
}
18+
}

lib/src/internals/methods.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
///
2+
/// [Author] Alex (https://github.com/AlexV525)
3+
/// [Date] 2021/9/30 17:01
4+
///
5+
import 'dart:developer';
6+
7+
import 'package:flutter/foundation.dart';
8+
9+
/// Log only in debug mode.
10+
/// 只在调试模式打印
11+
void realDebugPrint(dynamic message) {
12+
if (!kReleaseMode) {
13+
log('$message', name: 'CameraPicker - LOG');
14+
}
15+
}

lib/src/internals/type_defs.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
///
2+
/// [Author] Alex (https://github.com/AlexV525)
3+
/// [Date] 2021/9/30 17:04
4+
///
5+
import 'dart:async';
6+
import 'dart:io';
7+
8+
import 'package:flutter/widgets.dart';
9+
10+
import '../internals/enums.dart';
11+
12+
/// {@template wechat_camera_picker.SaveEntityCallback}
13+
/// The callback type define for saving entity in the viewer.
14+
/// 在查看器中保存图片时的回调
15+
///
16+
/// ### Notice about the implementation
17+
/// * After the callback is implemented, the default saving method
18+
/// won't called anymore.
19+
/// * Don't call `Navigator.of(context).pop/maybePop` without popping `null` or
20+
/// `AssetEntity`, otherwise there will be a type cast error occurred.
21+
///
22+
/// ### 在实现时需要注意
23+
/// * 实现该方法后,原本的保存方法不会再被调用;
24+
/// * 不要使用 `Navigator.of(context).pop/maybePop` 返回 `null``AssetEntity`
25+
/// 以外类型的内容,否则会抛出类型转换异常。
26+
/// {@endtemplate}
27+
typedef EntitySaveCallback = FutureOr<dynamic> Function({
28+
BuildContext context,
29+
CameraPickerViewType viewType,
30+
File file,
31+
});

lib/src/widget/camera_picker.dart renamed to lib/src/widgets/camera_picker.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import 'package:flutter/scheduler.dart';
1212
import 'package:flutter/services.dart';
1313

1414
import '../constants/constants.dart';
15-
import '../widget/circular_progress_bar.dart';
15+
import '../constants/styles.dart';
16+
import '../internals/enums.dart';
17+
import '../internals/extensions.dart';
18+
import '../internals/methods.dart';
19+
import '../internals/type_defs.dart';
20+
import '../widgets/circular_progress_bar.dart';
1621

1722
import 'builder/slide_page_transition_builder.dart';
1823
import 'camera_picker_viewer.dart';
@@ -686,7 +691,13 @@ class CameraPickerState extends State<CameraPicker>
686691
/// taking pictures.
687692
/// 仅当初始化成功且相机未在拍照时拍照。
688693
Future<void> takePicture() async {
689-
if (controller.value.isInitialized && !controller.value.isTakingPicture) {
694+
if (!controller.value.isInitialized) {
695+
throw StateError('Camera has not initialized.');
696+
}
697+
if (controller.value.isTakingPicture) {
698+
return;
699+
}
700+
try {
690701
final XFile _file = await controller.takePicture();
691702
// Delay disposing the controller to hold the preview.
692703
Future<void>.delayed(const Duration(milliseconds: 500), () {
@@ -707,6 +718,9 @@ class CameraPickerState extends State<CameraPicker>
707718
}
708719
initCameras(currentCamera);
709720
safeSetState(() {});
721+
} catch (e) {
722+
realDebugPrint('Error when preview the captured file: $e');
723+
rethrow;
710724
}
711725
}
712726

@@ -1152,7 +1166,7 @@ class CameraPickerState extends State<CameraPicker>
11521166
_shouldReverseLayout ? TextDirection.rtl : TextDirection.ltr,
11531167
children: <Widget>[
11541168
ExposurePointWidget(
1155-
key: ValueKey<int>(currentTimeStamp),
1169+
key: ValueKey<int>(DateTime.now().millisecondsSinceEpoch),
11561170
size: _pointWidth,
11571171
color: theme.iconTheme.color!,
11581172
),

0 commit comments

Comments
 (0)