Skip to content

Commit 4855672

Browse files
CopilotAlexV525
andcommitted
Add enableLivePhoto flag to AssetPickerConfig with full implementation
Co-authored-by: AlexV525 <[email protected]>
1 parent 2d23fff commit 4855672

File tree

7 files changed

+49
-2
lines changed

7 files changed

+49
-2
lines changed

lib/src/constants/config.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class AssetPickerConfig {
4040
this.assetsChangeRefreshPredicate,
4141
this.shouldAutoplayPreview = false,
4242
this.dragToSelect,
43+
this.enableLivePhoto = true,
4344
}) : assert(
4445
pickerTheme == null || themeColor == null,
4546
'pickerTheme and themeColor cannot be set at the same time.',
@@ -218,4 +219,14 @@ class AssetPickerConfig {
218219
/// 当 `maxAssets``1` 时,该功能不可用。
219220
/// {@endtemplate}
220221
final bool? dragToSelect;
222+
223+
/// {@template wechat_assets_picker.constants.AssetPickerConfig.enableLivePhoto}
224+
/// Whether to enable Live Photo functionality in the picker.
225+
/// 是否启用 Live Photo 功能
226+
///
227+
/// When set to `false`, Live Photo indicators and interactions will not be
228+
/// displayed throughout the picker.
229+
/// 当设置为 `false` 时,选择器中将不会显示 Live Photo 相关的标识和交互。
230+
/// {@endtemplate}
231+
final bool enableLivePhoto;
221232
}

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ class DefaultAssetPickerBuilderDelegate
848848
this.keepScrollOffset = false,
849849
this.shouldAutoplayPreview = false,
850850
this.dragToSelect,
851+
this.enableLivePhoto = true,
851852
}) {
852853
// Add the listener if [keepScrollOffset] is true.
853854
if (keepScrollOffset) {
@@ -914,6 +915,9 @@ class DefaultAssetPickerBuilderDelegate
914915
/// {@macro wechat_assets_picker.constants.AssetPickerConfig.dragToSelect}
915916
final bool? dragToSelect;
916917

918+
/// {@macro wechat_assets_picker.constants.AssetPickerConfig.enableLivePhoto}
919+
final bool enableLivePhoto;
920+
917921
/// [Duration] when triggering path switching.
918922
/// 切换路径时的动画时长
919923
Duration get switchingPathDuration => const Duration(milliseconds: 300);
@@ -1197,6 +1201,7 @@ class DefaultAssetPickerBuilderDelegate
11971201
maxAssets: p.maxAssets,
11981202
shouldReversePreview: revert,
11991203
shouldAutoplayPreview: shouldAutoplayPreview,
1204+
enableLivePhoto: enableLivePhoto,
12001205
useRootNavigator: viewerUseRootNavigator,
12011206
pageRouteSettings: viewerPageRouteSettings,
12021207
pageRouteBuilder: viewerPageRouteBuilder,
@@ -1921,7 +1926,8 @@ class DefaultAssetPickerBuilderDelegate
19211926
),
19221927
if (asset.type == AssetType.video) // 如果为视频则显示标识
19231928
videoIndicator(context, asset),
1924-
if (asset.isLivePhoto) buildLivePhotoIndicator(context, asset),
1929+
if (enableLivePhoto && asset.isLivePhoto)
1930+
buildLivePhotoIndicator(context, asset),
19251931
],
19261932
);
19271933
},

lib/src/delegates/asset_picker_delegate.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class AssetPickerDelegate {
123123
locale: Localizations.maybeLocaleOf(context),
124124
shouldAutoplayPreview: pickerConfig.shouldAutoplayPreview,
125125
dragToSelect: pickerConfig.dragToSelect,
126+
enableLivePhoto: pickerConfig.enableLivePhoto,
126127
),
127128
);
128129
final List<AssetEntity>? result = await Navigator.maybeOf(

lib/src/delegates/asset_picker_viewer_builder_delegate.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,16 @@ class DefaultAssetPickerViewerBuilderDelegate
392392
super.shouldReversePreview,
393393
super.selectPredicate,
394394
this.shouldAutoplayPreview = false,
395+
this.enableLivePhoto = true,
395396
});
396397

397398
/// Whether the preview should auto play.
398399
/// 预览是否自动播放
399400
final bool shouldAutoplayPreview;
400401

402+
/// {@macro wechat_assets_picker.constants.AssetPickerConfig.enableLivePhoto}
403+
final bool enableLivePhoto;
404+
401405
/// Thumb size for the preview of images in the viewer.
402406
/// 预览时图片的缩略图大小
403407
final ThumbnailSize? previewThumbnailSize;
@@ -436,6 +440,7 @@ class DefaultAssetPickerViewerBuilderDelegate
436440
delegate: this,
437441
previewThumbnailSize: previewThumbnailSize,
438442
shouldAutoplayPreview: shouldAutoplayPreview,
443+
enableLivePhoto: enableLivePhoto,
439444
),
440445
AssetType.video => VideoPageBuilder(
441446
asset: asset,

lib/src/widget/asset_picker_viewer.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class AssetPickerViewer<Asset, Path> extends StatefulWidget {
4545
PermissionRequestOption permissionRequestOption =
4646
const PermissionRequestOption(),
4747
bool shouldAutoplayPreview = false,
48+
bool enableLivePhoto = true,
4849
bool useRootNavigator = false,
4950
RouteSettings? pageRouteSettings,
5051
AssetPickerViewerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
@@ -74,6 +75,7 @@ class AssetPickerViewer<Asset, Path> extends StatefulWidget {
7475
shouldReversePreview: shouldReversePreview,
7576
selectPredicate: selectPredicate,
7677
shouldAutoplayPreview: shouldAutoplayPreview,
78+
enableLivePhoto: enableLivePhoto,
7779
),
7880
);
7981
final List<AssetEntity>? result = await Navigator.maybeOf(

lib/src/widget/builder/image_page_builder.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ImagePageBuilder extends StatefulWidget {
2424
required this.delegate,
2525
this.previewThumbnailSize,
2626
this.shouldAutoplayPreview = false,
27+
this.enableLivePhoto = true,
2728
});
2829

2930
/// Asset currently displayed.
@@ -38,6 +39,9 @@ class ImagePageBuilder extends StatefulWidget {
3839
/// 预览是否自动播放
3940
final bool shouldAutoplayPreview;
4041

42+
/// {@macro wechat_assets_picker.constants.AssetPickerConfig.enableLivePhoto}
43+
final bool enableLivePhoto;
44+
4145
@override
4246
State<ImagePageBuilder> createState() => _ImagePageBuilderState();
4347
}
@@ -48,7 +52,8 @@ class _ImagePageBuilderState extends State<ImagePageBuilder> {
4852

4953
bool get _isOriginal => widget.previewThumbnailSize == null;
5054

51-
bool get _isLivePhoto => widget.asset.isLivePhoto;
55+
bool get _isLivePhoto =>
56+
widget.enableLivePhoto && widget.asset.isLivePhoto;
5257

5358
@override
5459
void didUpdateWidget(ImagePageBuilder oldWidget) {

test/config_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,21 @@ void main() {
3333
expect(find.text('testPathNameBuilder'), findsOneWidget);
3434
});
3535
});
36+
37+
group('enableLivePhoto', () {
38+
test('defaults to true', () {
39+
const config = AssetPickerConfig();
40+
expect(config.enableLivePhoto, true);
41+
});
42+
43+
test('can be set to false', () {
44+
const config = AssetPickerConfig(enableLivePhoto: false);
45+
expect(config.enableLivePhoto, false);
46+
});
47+
48+
test('can be set to true explicitly', () {
49+
const config = AssetPickerConfig(enableLivePhoto: true);
50+
expect(config.enableLivePhoto, true);
51+
});
52+
});
3653
}

0 commit comments

Comments
 (0)