Skip to content

Commit eba5c0e

Browse files
committed
♻️ custom item -> spacial item
1 parent e07da55 commit eba5c0e

File tree

6 files changed

+67
-69
lines changed

6 files changed

+67
-69
lines changed

example/lib/pages/custom_picker_page.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,12 @@ class FileAssetPickerBuilder
531531
List<File> currentAssets,
532532
) {
533533
int currentIndex;
534-
switch (customItemPosition) {
535-
case CustomItemPosition.none:
536-
case CustomItemPosition.append:
534+
switch (specialItemPosition) {
535+
case SpecialItemPosition.none:
536+
case SpecialItemPosition.append:
537537
currentIndex = index;
538538
break;
539-
case CustomItemPosition.prepend:
539+
case SpecialItemPosition.prepend:
540540
currentIndex = index - 1;
541541
break;
542542
}
@@ -558,12 +558,12 @@ class FileAssetPickerBuilder
558558
@override
559559
int assetsGridItemCount(BuildContext context, List<File> currentAssets) {
560560
int length;
561-
switch (customItemPosition) {
562-
case CustomItemPosition.none:
561+
switch (specialItemPosition) {
562+
case SpecialItemPosition.none:
563563
length = currentAssets.length;
564564
break;
565-
case CustomItemPosition.prepend:
566-
case CustomItemPosition.append:
565+
case SpecialItemPosition.prepend:
566+
case SpecialItemPosition.append:
567567
length = currentAssets.length + 1;
568568
break;
569569
}

example/lib/pages/multi_assets_page.dart

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class _MultiAssetsPageState extends State<MultiAssetsPage> {
8888
maxAssets: maxAssetsCount,
8989
selectedAssets: assets,
9090
requestType: RequestType.common,
91-
customItemPosition: CustomItemPosition.prepend,
92-
customItemBuilder: (BuildContext context) {
91+
specialItemPosition: SpecialItemPosition.prepend,
92+
specialItemBuilder: (BuildContext context) {
9393
return GestureDetector(
9494
behavior: HitTestBehavior.opaque,
9595
onTap: () async {
@@ -173,8 +173,8 @@ class _MultiAssetsPageState extends State<MultiAssetsPage> {
173173
),
174174
PickMethodModel(
175175
icon: '➕',
176-
name: 'Prepend custom item',
177-
description: 'An custom item will prepend to the assets grid.',
176+
name: 'Prepend special item',
177+
description: 'A special item will prepend to the assets grid.',
178178
method: (
179179
BuildContext context,
180180
List<AssetEntity> assets,
@@ -184,8 +184,8 @@ class _MultiAssetsPageState extends State<MultiAssetsPage> {
184184
maxAssets: maxAssetsCount,
185185
selectedAssets: assets,
186186
requestType: RequestType.common,
187-
customItemPosition: CustomItemPosition.prepend,
188-
customItemBuilder: (BuildContext context) {
187+
specialItemPosition: SpecialItemPosition.prepend,
188+
specialItemBuilder: (BuildContext context) {
189189
return const Center(child: Text('Custom Widget'));
190190
},
191191
);
@@ -232,7 +232,7 @@ class _MultiAssetsPageState extends State<MultiAssetsPage> {
232232

233233
void removeAsset(int index) {
234234
setState(() {
235-
assets.remove(assets.elementAt(index));
235+
assets.removeAt(index);
236236
if (assets.isEmpty) {
237237
isDisplayingDetail = false;
238238
}
@@ -429,14 +429,7 @@ class _MultiAssetsPageState extends State<MultiAssetsPage> {
429429

430430
Widget _selectedAssetDeleteButton(int index) {
431431
return GestureDetector(
432-
onTap: () {
433-
setState(() {
434-
assets.removeAt(index);
435-
if (assetsLength == 0) {
436-
isDisplayingDetail = false;
437-
}
438-
});
439-
},
432+
onTap: () => removeAsset(index),
440433
child: DecoratedBox(
441434
decoration: BoxDecoration(
442435
borderRadius: BorderRadius.circular(4.0),

example/lib/pages/single_assets_page.dart

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class _SingleAssetPageState extends State<SingleAssetPage> {
8888
maxAssets: maxAssetsCount,
8989
selectedAssets: assets,
9090
requestType: RequestType.common,
91-
customItemPosition: CustomItemPosition.prepend,
92-
customItemBuilder: (BuildContext context) {
91+
specialItemPosition: SpecialItemPosition.prepend,
92+
specialItemBuilder: (BuildContext context) {
9393
return GestureDetector(
9494
behavior: HitTestBehavior.opaque,
9595
onTap: () async {
@@ -209,7 +209,7 @@ class _SingleAssetPageState extends State<SingleAssetPage> {
209209

210210
void removeAsset(int index) {
211211
setState(() {
212-
assets.remove(assets.elementAt(index));
212+
assets.removeAt(index);
213213
if (assets.isEmpty) {
214214
isDisplayingDetail = false;
215215
}
@@ -401,14 +401,7 @@ class _SingleAssetPageState extends State<SingleAssetPage> {
401401

402402
Widget _selectedAssetDeleteButton(int index) {
403403
return GestureDetector(
404-
onTap: () {
405-
setState(() {
406-
assets.removeAt(index);
407-
if (assetsLength == 0) {
408-
isDisplayingDetail = false;
409-
}
410-
});
411-
},
404+
onTap: () => removeAsset(index),
412405
child: DecoratedBox(
413406
decoration: BoxDecoration(
414407
borderRadius: BorderRadius.circular(4.0),

lib/src/constants/enums.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,17 @@
99
enum SpecialPickerType { wechatMoment }
1010

1111
/// Provide an item slot for custom widget insertion.
12-
/// 提供一个自定义位置供自定义item放入资源列表中。
13-
enum CustomItemPosition { none, prepend, append }
12+
/// 提供一个自定义位置供特殊item放入资源列表中。
13+
enum SpecialItemPosition {
14+
/// Not insert to the list.
15+
/// 不放入列表
16+
none,
17+
18+
/// Add as leading of the list.
19+
/// 在列表前放入
20+
prepend,
21+
22+
/// Add as trailing of the list.
23+
/// 在列表后放入
24+
append
25+
}

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ abstract class AssetPickerBuilderDelegate<A, P> {
2525
Color themeColor,
2626
AssetsPickerTextDelegate textDelegate,
2727
this.pickerTheme,
28-
this.customItemPosition = CustomItemPosition.none,
29-
this.customItemBuilder,
28+
this.specialItemPosition = SpecialItemPosition.none,
29+
this.specialItemBuilder,
3030
}) : assert(
3131
pickerTheme == null || themeColor == null,
3232
'Theme and theme color cannot be set at the same time.',
@@ -58,13 +58,13 @@ abstract class AssetPickerBuilderDelegate<A, P> {
5858
/// 通常情况下微信选择器使用的是暗色(暗色背景)的主题,但某些情况下开发者需要亮色或自定义主题。
5959
final ThemeData pickerTheme;
6060

61-
/// Allow users set custom item in the picker with several positions.
61+
/// Allow users set a special item in the picker with several positions.
6262
/// 允许用户在选择器中添加一个自定义item,并指定位置。
63-
final CustomItemPosition customItemPosition;
63+
final SpecialItemPosition specialItemPosition;
6464

65-
/// The widget builder for the custom item.
65+
/// The widget builder for the the special item.
6666
/// 自定义item的构造方法
67-
final WidgetBuilder customItemBuilder;
67+
final WidgetBuilder specialItemBuilder;
6868

6969
/// [ThemeData] for the picker.
7070
/// 选择器使用的主题
@@ -403,8 +403,8 @@ class DefaultAssetPickerBuilderDelegate
403403
Color themeColor,
404404
AssetsPickerTextDelegate textDelegate,
405405
ThemeData pickerTheme,
406-
CustomItemPosition customItemPosition = CustomItemPosition.none,
407-
WidgetBuilder customItemBuilder,
406+
SpecialItemPosition specialItemPosition = SpecialItemPosition.none,
407+
WidgetBuilder specialItemBuilder,
408408
this.previewThumbSize,
409409
this.specialPickerType,
410410
}) : assert(
@@ -421,8 +421,8 @@ class DefaultAssetPickerBuilderDelegate
421421
themeColor: themeColor,
422422
textDelegate: textDelegate,
423423
pickerTheme: pickerTheme,
424-
customItemPosition: customItemPosition,
425-
customItemBuilder: customItemBuilder,
424+
specialItemPosition: specialItemPosition,
425+
specialItemBuilder: specialItemBuilder,
426426
);
427427

428428
/// Thumb size for the preview of images in the viewer.
@@ -558,17 +558,17 @@ class DefaultAssetPickerBuilderDelegate
558558
}
559559

560560
/// There're several conditions within this builder:
561-
/// * Return [customItemBuilder] while the current path is all and
562-
/// [customItemPosition] is not equal to [CustomItemPosition.none].
561+
/// * Return [specialItemBuilder] while the current path is all and
562+
/// [specialItemPosition] is not equal to [SpecialItemPosition.none].
563563
/// * Return item builder according to the asset's type.
564564
/// * [AssetType.audio] -> [audioItemBuilder]
565565
/// * [AssetType.image], [AssetType.video] -> [imageAndVideoItemBuilder]
566566
/// * Load more assets when the index reached at third line counting
567567
/// backwards.
568568
///
569569
/// 资源构建有几个条件:
570-
/// * 当前路径是全部资源且 [customItemPosition] 不等于 [CustomItemPosition.none]
571-
/// 时,将会通过 [customItemBuilder] 构建内容。
570+
/// * 当前路径是全部资源且 [specialItemPosition] 不等于
571+
/// [SpecialItemPosition.none] 时,将会通过 [specialItemBuilder] 构建内容。
572572
/// * 根据资源类型返回对应类型的构建:
573573
/// * [AssetType.audio] -> [audioItemBuilder] 音频类型
574574
/// * [AssetType.image], [AssetType.video] -> [imageAndVideoItemBuilder]
@@ -587,12 +587,12 @@ class DefaultAssetPickerBuilderDelegate
587587
).currentPathEntity;
588588

589589
int currentIndex;
590-
switch (customItemPosition) {
591-
case CustomItemPosition.none:
592-
case CustomItemPosition.append:
590+
switch (specialItemPosition) {
591+
case SpecialItemPosition.none:
592+
case SpecialItemPosition.append:
593593
currentIndex = index;
594594
break;
595-
case CustomItemPosition.prepend:
595+
case SpecialItemPosition.prepend:
596596
currentIndex = index - 1;
597597
break;
598598
}
@@ -607,9 +607,9 @@ class DefaultAssetPickerBuilderDelegate
607607

608608
if (currentPathEntity.isAll) {
609609
if ((index == currentAssets.length &&
610-
customItemPosition == CustomItemPosition.append) ||
611-
(index == 0 && customItemPosition == CustomItemPosition.prepend)) {
612-
return customItemBuilder(context);
610+
specialItemPosition == SpecialItemPosition.append) ||
611+
(index == 0 && specialItemPosition == SpecialItemPosition.prepend)) {
612+
return specialItemBuilder(context);
613613
}
614614
}
615615

@@ -654,12 +654,12 @@ class DefaultAssetPickerBuilderDelegate
654654
return currentAssets.length;
655655
}
656656
int length;
657-
switch (customItemPosition) {
658-
case CustomItemPosition.none:
657+
switch (specialItemPosition) {
658+
case SpecialItemPosition.none:
659659
length = currentAssets.length;
660660
break;
661-
case CustomItemPosition.prepend:
662-
case CustomItemPosition.append:
661+
case SpecialItemPosition.prepend:
662+
case SpecialItemPosition.append:
663663
length = currentAssets.length + 1;
664664
break;
665665
}

lib/src/widget/asset_picker.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class AssetPicker<A, P> extends StatelessWidget {
3939
SortPathDelegate sortPathDelegate,
4040
AssetsPickerTextDelegate textDelegate,
4141
FilterOptionGroup filterOptions,
42-
WidgetBuilder customItemBuilder,
43-
CustomItemPosition customItemPosition = CustomItemPosition.none,
42+
WidgetBuilder specialItemBuilder,
43+
SpecialItemPosition specialItemPosition = SpecialItemPosition.none,
4444
Curve routeCurve = Curves.easeIn,
4545
Duration routeDuration = const Duration(milliseconds: 300),
4646
}) async {
@@ -70,10 +70,10 @@ class AssetPicker<A, P> extends StatelessWidget {
7070
requestType ??= RequestType.image;
7171
}
7272
}
73-
if ((customItemBuilder == null &&
74-
customItemPosition != CustomItemPosition.none) ||
75-
(customItemBuilder != null &&
76-
customItemPosition == CustomItemPosition.none)) {
73+
if ((specialItemBuilder == null &&
74+
specialItemPosition != SpecialItemPosition.none) ||
75+
(specialItemBuilder != null &&
76+
specialItemPosition == SpecialItemPosition.none)) {
7777
throw ArgumentError('Custom item didn\'t set properly.');
7878
}
7979

@@ -103,8 +103,8 @@ class AssetPicker<A, P> extends StatelessWidget {
103103
pickerTheme: pickerTheme,
104104
previewThumbSize: previewThumbSize,
105105
specialPickerType: specialPickerType,
106-
customItemPosition: customItemPosition,
107-
customItemBuilder: customItemBuilder,
106+
specialItemPosition: specialItemPosition,
107+
specialItemBuilder: specialItemBuilder,
108108
),
109109
),
110110
);

0 commit comments

Comments
 (0)