save_to_album_handler.dart
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import 'package:appframe/services/dispatcher.dart';
import 'package:gallery_saver_plus/gallery_saver.dart';
class SaveToAlbumHandler implements MessageHandler {
@override
Future<dynamic> handleMessage(dynamic params) async {
if (params is! Map<String, dynamic>) {
throw Exception('参数错误');
}
var filePath = params['filePath'] as String?;
if (filePath == null || filePath.isEmpty) {
return false;
}
bool isVideo =
filePath.endsWith('.mp4') ||
filePath.endsWith('.avi') ||
filePath.endsWith('.mov') ||
filePath.endsWith('.mkv') ||
filePath.endsWith('.wmv') ||
filePath.endsWith('.flv') ||
filePath.endsWith('.webm') ||
filePath.endsWith('.m4v') ||
filePath.endsWith('.3gp');
try {
if (isVideo) {
final bool? success = await GallerySaver.saveVideo(filePath);
return success ?? false;
} else {
final bool? success = await GallerySaver.saveImage(filePath);
return success ?? false;
}
} catch (e) {
print(e);
return false;
}
}
}