@@ -57,7 +57,12 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
57
57
),
58
58
themeColor = pickerTheme? .colorScheme.secondary ??
59
59
themeColor ??
60
- defaultThemeColorWeChat {
60
+ defaultThemeColorWeChat,
61
+ prependSpecialItems = specialItems
62
+ .where (
63
+ (item) => item.position == SpecialItemPosition .prepend,
64
+ )
65
+ .toList () {
61
66
Singleton .textDelegate =
62
67
textDelegate ?? assetPickerTextDelegateFromLocale (locale);
63
68
}
@@ -86,7 +91,7 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
86
91
87
92
/// List of special items.
88
93
/// 自定义item列表
89
- final List <SpecialItem > specialItems;
94
+ final List <SpecialItem < Path > > specialItems;
90
95
91
96
/// Indicates the loading status for the builder.
92
97
/// 指示目前加载的状态
@@ -126,6 +131,10 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
126
131
final AssetsChangeRefreshPredicate <AssetPathEntity >?
127
132
assetsChangeRefreshPredicate;
128
133
134
+ /// List of prepend special items.
135
+ /// 前置自定义item列表
136
+ final List <SpecialItem <Path >> prependSpecialItems;
137
+
129
138
/// [ThemeData] for the picker.
130
139
/// 选择器使用的主题
131
140
ThemeData get theme => pickerTheme ?? AssetPicker .themeData (themeColor);
@@ -220,14 +229,6 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
220
229
AssetPickerTextDelegate get semanticsTextDelegate =>
221
230
Singleton .textDelegate.semanticsTextDelegate;
222
231
223
- Iterable <SpecialItem > get prepandSpecialItems => specialItems.where (
224
- (model) => model.itemPosition == SpecialItemPosition .prepend,
225
- );
226
-
227
- Iterable <SpecialItem > get appendSpecialItems => specialItems.where (
228
- (model) => model.itemPosition == SpecialItemPosition .append,
229
- );
230
-
231
232
/// Keep a `initState` method to sync with [State] .
232
233
/// 保留一个 `initState` 方法与 [State] 同步。
233
234
@mustCallSuper
@@ -759,7 +760,7 @@ class DefaultAssetPickerBuilderDelegate
759
760
this .specialPickerType,
760
761
this .keepScrollOffset = false ,
761
762
this .shouldAutoplayPreview = false ,
762
- this .specialItems = const [],
763
+ super .specialItems = const [],
763
764
}) {
764
765
// Add the listener if [keepScrollOffset] is true.
765
766
if (keepScrollOffset) {
@@ -818,11 +819,6 @@ class DefaultAssetPickerBuilderDelegate
818
819
/// 预览是否自动播放
819
820
final bool shouldAutoplayPreview;
820
821
821
- /// List of special items.
822
- /// 自定义item列表
823
- @override
824
- final List <SpecialItem > specialItems;
825
-
826
822
/// [Duration] when triggering path switching.
827
823
/// 切换路径时的动画时长
828
824
Duration get switchingPathDuration => const Duration (milliseconds: 300 );
@@ -1236,29 +1232,23 @@ class DefaultAssetPickerBuilderDelegate
1236
1232
builder: (context, wrapper, _) {
1237
1233
// First, we need the count of the assets.
1238
1234
int totalCount = wrapper? .assetCount ?? 0 ;
1239
- final List <
1240
- ({SpecialItemPosition specialItemPosition, Widget specialItem})>
1241
- specialItemModels = [];
1242
- // If user chose a special item's position, add 1 count.
1243
- if (specialItems.isNotEmpty) {
1244
- for (final item in specialItems) {
1245
- final specialItem = item.itemBuilder? .call (
1246
- context,
1247
- wrapper? .path,
1248
- totalCount,
1249
- isPermissionLimited,
1250
- );
1251
- if (specialItem != null ) {
1252
- specialItemModels.add (
1253
- (
1254
- specialItemPosition: item.itemPosition,
1255
- specialItem: specialItem,
1256
- ),
1235
+
1236
+ final List <SpecialItemModel > specialItemModels = specialItems
1237
+ .map ((item) {
1238
+ return (
1239
+ position: item.position,
1240
+ item: item.builder? .call (
1241
+ context,
1242
+ wrapper? .path,
1243
+ totalCount,
1244
+ isPermissionLimited,
1245
+ )
1257
1246
);
1258
- totalCount += 1 ;
1259
- }
1260
- }
1261
- }
1247
+ })
1248
+ .whereType <SpecialItemModel >()
1249
+ .toList ();
1250
+
1251
+ totalCount += specialItemModels.length;
1262
1252
1263
1253
if (totalCount == 0 && specialItemModels.isEmpty) {
1264
1254
return loadingIndicator (context);
@@ -1419,8 +1409,7 @@ class DefaultAssetPickerBuilderDelegate
1419
1409
BuildContext context,
1420
1410
int index,
1421
1411
List <AssetEntity > currentAssets, {
1422
- List <({SpecialItemPosition specialItemPosition, Widget specialItem})>
1423
- specialItemModels = const [],
1412
+ List <SpecialItemModel > specialItemModels = const [],
1424
1413
}) {
1425
1414
final DefaultAssetPickerProvider p =
1426
1415
context.read <DefaultAssetPickerProvider >();
@@ -1429,22 +1418,22 @@ class DefaultAssetPickerBuilderDelegate
1429
1418
final AssetPathEntity ? currentPathEntity = currentWrapper? .path;
1430
1419
1431
1420
final prepandSpecialItemModels = specialItemModels.where (
1432
- (model) => model.specialItemPosition == SpecialItemPosition .prepend,
1421
+ (model) => model.position == SpecialItemPosition .prepend,
1433
1422
);
1434
1423
final appendSpecialItemModels = specialItemModels.where (
1435
- (model) => model.specialItemPosition == SpecialItemPosition .append,
1424
+ (model) => model.position == SpecialItemPosition .append,
1436
1425
);
1437
1426
1438
1427
if (specialItemModels.isNotEmpty) {
1439
1428
if (prepandSpecialItemModels.isNotEmpty) {
1440
1429
if (index < prepandSpecialItemModels.length) {
1441
- return specialItemModels[index].specialItem ;
1430
+ return specialItemModels[index].item ;
1442
1431
}
1443
1432
}
1444
1433
1445
1434
if (appendSpecialItemModels.isNotEmpty) {
1446
1435
if (index >= length + prepandSpecialItemModels.length) {
1447
- return specialItemModels[index - length].specialItem ;
1436
+ return specialItemModels[index - length].item ;
1448
1437
}
1449
1438
}
1450
1439
}
@@ -1488,8 +1477,8 @@ class DefaultAssetPickerBuilderDelegate
1488
1477
}
1489
1478
1490
1479
int semanticIndex (int index) {
1491
- if (prepandSpecialItems .isNotEmpty) {
1492
- return index - prepandSpecialItems .length + 1 ;
1480
+ if (prependSpecialItems .isNotEmpty) {
1481
+ return index - prependSpecialItems .length + 1 ;
1493
1482
}
1494
1483
1495
1484
return index;
@@ -1584,8 +1573,8 @@ class DefaultAssetPickerBuilderDelegate
1584
1573
}) {
1585
1574
int index = assets.indexWhere ((AssetEntity e) => e.id == id);
1586
1575
1587
- if (prepandSpecialItems .isNotEmpty) {
1588
- index += prepandSpecialItems .length;
1576
+ if (prependSpecialItems .isNotEmpty) {
1577
+ index += prependSpecialItems .length;
1589
1578
}
1590
1579
index += placeholderCount;
1591
1580
return index;
@@ -1596,8 +1585,7 @@ class DefaultAssetPickerBuilderDelegate
1596
1585
required BuildContext context,
1597
1586
required List <AssetEntity > assets,
1598
1587
int placeholderCount = 0 ,
1599
- List <({SpecialItemPosition specialItemPosition, Widget specialItem})>
1600
- specialItemModels = const [],
1588
+ List <SpecialItemModel > specialItemModels = const [],
1601
1589
}) {
1602
1590
final PathWrapper <AssetPathEntity >? currentWrapper = context
1603
1591
.select <DefaultAssetPickerProvider , PathWrapper <AssetPathEntity >?>(
0 commit comments