-
-
Notifications
You must be signed in to change notification settings - Fork 460
/
multi_assets_page.dart
111 lines (102 loc) · 3.9 KB
/
multi_assets_page.dart
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2019 The FlutterCandies author. All rights reserved.
// Use of this source code is governed by an Apache license that can be found
// in the LICENSE file.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
import '../constants/extensions.dart';
import '../constants/picker_method.dart';
import 'page_mixin.dart';
class MultiAssetsPage extends StatefulWidget {
const MultiAssetsPage({super.key});
@override
State<MultiAssetsPage> createState() => _MultiAssetsPageState();
}
class _MultiAssetsPageState extends State<MultiAssetsPage>
with AutomaticKeepAliveClientMixin, ExamplePageMixin {
@override
String get noticeText => 'lib/pages/multi_assets_page.dart';
@override
int get maxAssetsCount => 9;
/// Check each method's source code for more details.
@override
List<PickMethod> pickMethods(BuildContext context) {
return <PickMethod>[
PickMethod.common(context, maxAssetsCount),
PickMethod.image(context, maxAssetsCount),
PickMethod.video(context, maxAssetsCount),
PickMethod.audio(context, maxAssetsCount),
if (Platform.isIOS || Platform.isMacOS)
PickMethod.livePhoto(context, maxAssetsCount),
PickMethod.camera(
context: context,
maxAssetsCount: maxAssetsCount,
handleResult: (BuildContext context, AssetEntity result) =>
Navigator.maybeOf(context)?.pop(<AssetEntity>[...assets, result]),
),
PickMethod.cameraAndStay(context, maxAssetsCount),
PickMethod.changeLanguages(context, maxAssetsCount),
PickMethod.threeItemsGrid(context, maxAssetsCount),
PickMethod.prependItem(context, maxAssetsCount),
PickMethod(
icon: '🎭',
name: context.l10n.pickMethodWeChatMomentName,
description: context.l10n.pickMethodWeChatMomentDescription,
method: (BuildContext context, List<AssetEntity> assets) {
return AssetPicker.pickAssets(
context,
pickerConfig: AssetPickerConfig(
maxAssets: maxAssetsCount,
specialPickerType: SpecialPickerType.wechatMoment,
),
);
},
),
PickMethod.noPreview(context, maxAssetsCount),
PickMethod.customizableTheme(context, maxAssetsCount),
PickMethod.pathNameBuilder(context, maxAssetsCount),
PickMethod.customFilterOptions(context, maxAssetsCount),
PickMethod.preventGIFPicked(context, maxAssetsCount),
PickMethod.keepScrollOffset(
context: context,
delegate: () => keepScrollDelegate!,
onPermission: (PermissionState state) {
keepScrollDelegate ??= DefaultAssetPickerBuilderDelegate(
provider: keepScrollProvider,
initialPermission: state,
keepScrollOffset: true,
);
},
onLongPress: () {
keepScrollProvider.dispose();
keepScrollProvider = DefaultAssetPickerProvider();
keepScrollDelegate?.dispose();
keepScrollDelegate = null;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Resources have been released')),
);
},
),
PickMethod(
icon: '🎚',
name: context.l10n.pickMethodCustomImagePreviewThumbSizeName,
description:
context.l10n.pickMethodCustomImagePreviewThumbSizeDescription,
method: (BuildContext context, List<AssetEntity> assets) {
return AssetPicker.pickAssets(
context,
pickerConfig: AssetPickerConfig(
maxAssets: maxAssetsCount,
selectedAssets: assets,
requestType: RequestType.image,
gridThumbnailSize: const ThumbnailSize.square(80),
previewThumbnailSize: const ThumbnailSize.square(150),
),
);
},
),
];
}
@override
bool get wantKeepAlive => true;
}