@@ -252,7 +252,6 @@ abstract class AssetPickerBuilderDelegate<A, P> {
252
252
/// The main grid view builder for assets.
253
253
/// 主要的资源查看网格部件
254
254
Widget assetsGridBuilder (BuildContext context) {
255
- final int hashCode = provider.currentPathEntity? .hashCode ?? 0 ;
256
255
return ColoredBox (
257
256
color: theme.canvasColor,
258
257
child: Selector <AssetPickerProvider <A , P >, List <A >>(
@@ -270,16 +269,22 @@ abstract class AssetPickerBuilderDelegate<A, P> {
270
269
SliverGrid (
271
270
delegate: SliverChildBuilderDelegate (
272
271
(_, int index) => Builder (
273
- key: ValueKey <int >(index + hashCode),
274
272
builder: (BuildContext c) => assetGridItemBuilder (
275
273
c,
276
274
index,
277
275
currentAssets,
278
276
),
279
277
),
280
278
childCount: assetsGridItemCount (_, currentAssets),
281
- findChildIndexCallback: (Key key) =>
282
- (key as ValueKey <int >).value - hashCode,
279
+ findChildIndexCallback: (Key ? key) {
280
+ if (key is ValueKey <String >) {
281
+ return findChildIndexBuilder (
282
+ key.value,
283
+ currentAssets,
284
+ );
285
+ }
286
+ return null ;
287
+ },
283
288
),
284
289
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount (
285
290
crossAxisCount: gridCount,
@@ -299,6 +304,10 @@ abstract class AssetPickerBuilderDelegate<A, P> {
299
304
);
300
305
}
301
306
307
+ /// Indicates how would the grid found a reusable [RenderObject] through [id] .
308
+ /// 为 Grid 布局指示如何找到可复用的 [RenderObject] 。
309
+ int findChildIndexBuilder (String id, List <A > currentAssets);
310
+
302
311
/// The function which return items count for the assets' grid.
303
312
/// 为资源列表提供内容数量计算的方法
304
313
int assetsGridItemCount (BuildContext context, List <A > currentAssets);
@@ -697,6 +706,7 @@ class DefaultAssetPickerBuilderDelegate
697
706
break ;
698
707
}
699
708
return Stack (
709
+ key: ValueKey <String >(asset.id),
700
710
children: < Widget > [
701
711
builder,
702
712
if (! isWeChatMoment || asset.type != AssetType .video)
@@ -705,6 +715,15 @@ class DefaultAssetPickerBuilderDelegate
705
715
);
706
716
}
707
717
718
+ @override
719
+ int findChildIndexBuilder (String id, List <AssetEntity > currentAssets) {
720
+ int index = currentAssets.indexWhere ((AssetEntity e) => e.id == id);
721
+ if (specialItemPosition == SpecialItemPosition .prepend) {
722
+ index += 1 ;
723
+ }
724
+ return index;
725
+ }
726
+
708
727
@override
709
728
int assetsGridItemCount (
710
729
BuildContext context,
0 commit comments