@@ -49,6 +49,7 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
49
49
this .allowSpecialItemWhenEmpty = false ,
50
50
this .keepScrollOffset = false ,
51
51
this .selectPredicate,
52
+ this .shouldRevertGrid,
52
53
}) : assert (
53
54
pickerTheme == null || themeColor == null ,
54
55
'Theme and theme color cannot be set at the same time.' ,
@@ -119,6 +120,13 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
119
120
/// [assetsGridBuilder] 用于定位 [ScrollView.center] 的 [GlobalKey]
120
121
final GlobalKey gridRevertKey = GlobalKey ();
121
122
123
+ /// Whether the assets grid should revert.
124
+ /// 判断资源网格是否需要倒序排列
125
+ ///
126
+ /// [Null] means judging by [isAppleOS] .
127
+ /// 使用 [Null] 即使用 [isAppleOS] 进行判断。
128
+ final bool ? shouldRevertGrid;
129
+
122
130
/// [ThemeData] for the picker.
123
131
/// 选择器使用的主题
124
132
ThemeData get theme => pickerTheme ?? AssetPicker .themeData (themeColor);
@@ -186,6 +194,8 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
186
194
/// 当前的权限是否为受限
187
195
bool get isPermissionLimited => permission.value == PermissionState .limited;
188
196
197
+ bool get effectiveShouldRevertGrid => shouldRevertGrid ?? isAppleOS;
198
+
189
199
/// The listener to track the scroll position of the [gridScrollController]
190
200
/// if [keepScrollOffset] is true.
191
201
/// 当 [keepScrollOffset] 为 true 时,跟踪 [gridScrollController] 位置的监听。
@@ -357,7 +367,7 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
357
367
/// 默认情况下,在 iOS/macOS 上方向会反向。
358
368
TextDirection effectiveGridDirection (BuildContext context) {
359
369
final TextDirection _od = Directionality .of (context);
360
- if (isAppleOS ) {
370
+ if (effectiveShouldRevertGrid ) {
361
371
if (_od == TextDirection .ltr) {
362
372
return TextDirection .rtl;
363
373
}
@@ -642,6 +652,7 @@ class DefaultAssetPickerBuilderDelegate
642
652
bool allowSpecialItemWhenEmpty = false ,
643
653
bool keepScrollOffset = false ,
644
654
AssetSelectPredicate <AssetEntity >? selectPredicate,
655
+ bool ? shouldRevertGrid,
645
656
this .gridThumbSize = Constants .defaultGridThumbSize,
646
657
this .previewThumbSize,
647
658
this .specialPickerType,
@@ -662,6 +673,7 @@ class DefaultAssetPickerBuilderDelegate
662
673
allowSpecialItemWhenEmpty: allowSpecialItemWhenEmpty,
663
674
keepScrollOffset: keepScrollOffset,
664
675
selectPredicate: selectPredicate,
676
+ shouldRevertGrid: shouldRevertGrid,
665
677
);
666
678
667
679
/// Thumbnail size in the grid.
@@ -840,11 +852,11 @@ class DefaultAssetPickerBuilderDelegate
840
852
path? .isAll == true ) {
841
853
totalCount += 1 ;
842
854
}
843
- // Then we use the [totalCount] to calculate how many placeholders we need.
855
+ // Then we use the [totalCount] to calculate placeholders we need.
844
856
final int placeholderCount;
845
- if (isAppleOS && totalCount % gridCount != 0 ) {
846
- // When there are left items that not filled into one row, filled the row
847
- // with placeholders.
857
+ if (effectiveShouldRevertGrid && totalCount % gridCount != 0 ) {
858
+ // When there are left items that not filled into one row,
859
+ // filled the row with placeholders.
848
860
placeholderCount = gridCount - totalCount % gridCount;
849
861
} else {
850
862
// Otherwise, we don't need placeholders.
@@ -863,7 +875,7 @@ class DefaultAssetPickerBuilderDelegate
863
875
delegate: SliverChildBuilderDelegate (
864
876
(_, int index) => Builder (
865
877
builder: (BuildContext c) {
866
- if (isAppleOS ) {
878
+ if (effectiveShouldRevertGrid ) {
867
879
if (index < placeholderCount) {
868
880
return const SizedBox .shrink ();
869
881
}
@@ -933,25 +945,27 @@ class DefaultAssetPickerBuilderDelegate
933
945
selector: (_, DefaultAssetPickerProvider p) =>
934
946
p.currentAssets,
935
947
builder: (_, List <AssetEntity > assets, __) {
948
+ final SliverGap _bottomGap = SliverGap .v (
949
+ context.bottomPadding + bottomSectionHeight,
950
+ );
936
951
return CustomScrollView (
937
952
physics: const AlwaysScrollableScrollPhysics (),
938
953
controller: gridScrollController,
939
- anchor: isAppleOS ? anchor : 0 ,
940
- center: isAppleOS ? gridRevertKey : null ,
954
+ anchor: effectiveShouldRevertGrid ? anchor : 0 ,
955
+ center: effectiveShouldRevertGrid ? gridRevertKey : null ,
941
956
slivers: < Widget > [
942
957
if (isAppleOS)
943
958
SliverGap .v (context.topPadding + kToolbarHeight),
944
959
_sliverGrid (_, assets),
945
960
// Ignore the gap when the [anchor] is not equal to 1.
946
- if (isAppleOS && anchor == 1 )
947
- SliverGap .v (
948
- context.bottomPadding + bottomSectionHeight,
949
- ),
950
- if (isAppleOS)
961
+ if (effectiveShouldRevertGrid && anchor == 1 )
962
+ _bottomGap,
963
+ if (effectiveShouldRevertGrid)
951
964
SliverToBoxAdapter (
952
965
key: gridRevertKey,
953
966
child: const SizedBox .shrink (),
954
967
),
968
+ if (isAppleOS && ! effectiveShouldRevertGrid) _bottomGap,
955
969
],
956
970
);
957
971
},
0 commit comments