@@ -19,6 +19,8 @@ abstract class AssetPickerBuilderDelegate<A, P> {
19
19
Color themeColor,
20
20
AssetsPickerTextDelegate textDelegate,
21
21
this .pickerTheme,
22
+ this .customItemPosition = CustomItemPosition .none,
23
+ this .customItemBuilder,
22
24
}) : assert (
23
25
pickerTheme == null || themeColor == null ,
24
26
'Theme and theme color cannot be set at the same time.' ,
@@ -50,6 +52,14 @@ abstract class AssetPickerBuilderDelegate<A, P> {
50
52
/// 通常情况下微信选择器使用的是暗色(暗色背景)的主题,但某些情况下开发者需要亮色或自定义主题。
51
53
final ThemeData pickerTheme;
52
54
55
+ /// Allow users set custom item in the picker with several positions.
56
+ /// 允许用户在选择器中添加一个自定义item,并指定位置。
57
+ final CustomItemPosition customItemPosition;
58
+
59
+ /// The widget builder for the custom item.
60
+ /// 自定义item的构造方法
61
+ final WidgetBuilder customItemBuilder;
62
+
53
63
/// [ThemeData] for the picker.
54
64
/// 选择器使用的主题
55
65
ThemeData get theme => pickerTheme ?? AssetPicker .themeData (themeColor);
@@ -387,10 +397,10 @@ class DefaultAssetPickerBuilderDelegate
387
397
Color themeColor,
388
398
AssetsPickerTextDelegate textDelegate,
389
399
ThemeData pickerTheme,
400
+ CustomItemPosition customItemPosition = CustomItemPosition .none,
401
+ WidgetBuilder customItemBuilder,
390
402
this .previewThumbSize,
391
403
this .specialPickerType,
392
- this .customItemPosition = CustomItemPosition .none,
393
- this .customItemBuilder,
394
404
}) : assert (
395
405
provider != null ,
396
406
'AssetPickerProvider must be provided and not null.' ,
@@ -405,6 +415,8 @@ class DefaultAssetPickerBuilderDelegate
405
415
themeColor: themeColor,
406
416
textDelegate: textDelegate,
407
417
pickerTheme: pickerTheme,
418
+ customItemPosition: customItemPosition,
419
+ customItemBuilder: customItemBuilder,
408
420
);
409
421
410
422
/// Thumb size for the preview of images in the viewer.
@@ -431,14 +443,6 @@ class DefaultAssetPickerBuilderDelegate
431
443
/// * [SpecialPickerType.wechatMoment] 微信朋友圈模式。当用户选择了视频,将不能选择图片。
432
444
final SpecialPickerType specialPickerType;
433
445
434
- /// The widget builder for the custom item.
435
- /// 自定义item的构造方法
436
- final WidgetBuilder customItemBuilder;
437
-
438
- /// Allow users set custom item in the picker with several positions.
439
- /// 允许用户在选择器中添加一个自定义item,并指定位置。
440
- final CustomItemPosition customItemPosition;
441
-
442
446
/// [Duration] when triggering path switching.
443
447
/// 切换路径时的动画时长
444
448
Duration get switchingPathDuration => kThemeAnimationDuration * 1.5 ;
@@ -570,10 +574,11 @@ class DefaultAssetPickerBuilderDelegate
570
574
int index,
571
575
List <AssetEntity > currentAssets,
572
576
) {
573
- final AssetPathEntity currentPath = Provider .of <DefaultAssetPickerProvider >(
577
+ final AssetPathEntity currentPathEntity =
578
+ Provider .of <DefaultAssetPickerProvider >(
574
579
context,
575
580
listen: false ,
576
- ).currentPath ;
581
+ ).currentPathEntity ;
577
582
578
583
int currentIndex;
579
584
switch (customItemPosition) {
@@ -585,7 +590,7 @@ class DefaultAssetPickerBuilderDelegate
585
590
currentIndex = index - 1 ;
586
591
break ;
587
592
}
588
- if (! currentPath .isAll) {
593
+ if (! currentPathEntity .isAll) {
589
594
currentIndex = index;
590
595
}
591
596
@@ -594,7 +599,7 @@ class DefaultAssetPickerBuilderDelegate
594
599
provider.loadMoreAssets ();
595
600
}
596
601
597
- if (currentPath .isAll) {
602
+ if (currentPathEntity .isAll) {
598
603
if ((index == currentAssets.length &&
599
604
customItemPosition == CustomItemPosition .append) ||
600
605
(index == 0 && customItemPosition == CustomItemPosition .prepend)) {
@@ -631,14 +636,15 @@ class DefaultAssetPickerBuilderDelegate
631
636
BuildContext context,
632
637
List <AssetEntity > currentAssets,
633
638
) {
634
- final AssetPathEntity currentPath = Provider .of <DefaultAssetPickerProvider >(
639
+ final AssetPathEntity currentPathEntity =
640
+ Provider .of <DefaultAssetPickerProvider >(
635
641
context,
636
642
listen: false ,
637
- ).currentPath ;
643
+ ).currentPathEntity ;
638
644
639
645
/// Return actual length if current path is all.
640
646
/// 如果当前目录是全部内容,则返回实际的内容数量。
641
- if (! currentPath .isAll) {
647
+ if (! currentPathEntity .isAll) {
642
648
return currentAssets.length;
643
649
}
644
650
int length;
@@ -867,9 +873,8 @@ class DefaultAssetPickerBuilderDelegate
867
873
ignoring: ! isSwitchingPath,
868
874
child: GestureDetector (
869
875
onTap: () {
870
- context
871
- .read <AssetPickerProvider <AssetEntity , AssetPathEntity >>()
872
- .isSwitchingPath = false ;
876
+ context.read <DefaultAssetPickerProvider >().isSwitchingPath =
877
+ false ;
873
878
},
874
879
child: AnimatedOpacity (
875
880
duration: switchingPathDuration,
@@ -977,10 +982,10 @@ class DefaultAssetPickerBuilderDelegate
977
982
child: Row (
978
983
mainAxisSize: MainAxisSize .min,
979
984
children: < Widget > [
980
- if (provider.currentPath != null )
985
+ if (provider.currentPathEntity != null )
981
986
Flexible (
982
987
child: Text (
983
- provider.currentPath .name ?? '' ,
988
+ provider.currentPathEntity .name ?? '' ,
984
989
style: const TextStyle (
985
990
fontSize: 18.0 ,
986
991
fontWeight: FontWeight .normal,
@@ -1107,7 +1112,7 @@ class DefaultAssetPickerBuilderDelegate
1107
1112
BuildContext _,
1108
1113
DefaultAssetPickerProvider provider,
1109
1114
) =>
1110
- provider.currentPath ,
1115
+ provider.currentPathEntity ,
1111
1116
builder: (
1112
1117
BuildContext _,
1113
1118
AssetPathEntity currentPathEntity,
0 commit comments