Skip to content

Commit f780894

Browse files
✨ Add gridThumbSize (#117)
Co-authored-by: Alex Li <[email protected]>
1 parent 21e22a6 commit f780894

File tree

8 files changed

+37
-16
lines changed

8 files changed

+37
-16
lines changed

README-ZH.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ platform :ios, '9.0'
153153
| selectedAssets | `List<AssetEntity>?` | 已选的资源。确保不重复选择。如果你允许重复选择,请将其置空。 | `null` |
154154
| maxAssets | `int` | 最多选择的图片数量 | 9 |
155155
| pageSize | `int` | 分页加载时每页加载的资源数量。**必须为网格数的倍数。** 设置为`null`可以取消分页。 | 320 (80 * 4) |
156-
| pathThumbSize | `int` | 选择器的缩略图大小 | 80 |
156+
| gridThumbSize | `int` | 预览网格的缩略图大小 | 200 |
157+
| pathThumbSize | `int` | 路径选择器的缩略图大小 | 80 |
158+
| previewThumbSize | `List<int>?` | 预览时图片的缩略图大小 | `null` |
157159
| gridCount | `int` | 选择器网格数量 | 4 |
158160
| requestType | `RequestType` | 选择器选择资源的类型 | `RequestType.image` |
159-
| previewThumbSize | `List<int>?` | 预览时图片的缩略图大小 | `null` |
160161
| specialPickerType | `SpecialPickerType?` | 提供一些特殊的选择器类型以整合非常规的选择行为 | `null` |
161162
| themeColor | `Color?` | 选择器的主题色 | `Color(0xff00bc56)` |
162163
| pickerTheme | `ThemeData?` | 选择器的主题提供,包括查看器 | `null` |

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,11 @@ platform :osx, '10.15'
181181
| selectedAssets | `List<AssetEntity>?` | Selected assets. Prevent duplicate selection. If you don't need to prevent duplicate selection, just don't pass it. | `null` |
182182
| maxAssets | `int` | Maximum asset that the picker can pick. | 9 |
183183
| pageSize | `int?` | Number of assets per page. **Must be a multiple of `gridCount`**. | 320 (80 * 4) |
184-
| pathThumbSize | `int` | Thumbnail size. | 80 |
184+
| gridThumbSize | `int` | Thumbnail size for the grid's item. | 200 |
185+
| pathThumbSize | `int` | Thumbnail size for the path selector. | 80 |
186+
| previewThumbSize | `List<int>?` | Preview thumbnail size in the viewer. | `null` |
185187
| gridCount | `int` | Grid count in picker. | 4 |
186188
| requestType | `RequestType` | Request type for picker. | `RequestType.image` |
187-
| previewThumbSize | `List<int>?` | Preview thumbnail size in the viewer. | `null` |
188189
| specialPickerType | `SpacialPickerType?` | Provides the option to integrate a custom picker type. | `null` |
189190
| themeColor | `Color?` | Main theme color for the picker. | `Color(0xff00bc56)` |
190191
| pickerTheme | `ThemeData?` | Theme data provider for the picker and the viewer. | `null` |

example/lib/pages/multi_assets_page.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ class _MultiAssetsPageState extends State<MultiAssetsPage>
5757
PickMethodModel(
5858
icon: '🎚',
5959
name: 'Custom image preview thumb size',
60-
description:
61-
'You can reduce the thumb size to get more quickly load speed.',
60+
description: 'You can reduce the thumb size to get faster load speed.',
6261
method: (BuildContext context, List<AssetEntity> assets) {
6362
return AssetPicker.pickAssets(
6463
context,
6564
maxAssets: maxAssetsCount,
6665
selectedAssets: assets,
6766
requestType: RequestType.image,
68-
previewThumbSize: const <int>[300, 300],
67+
previewThumbSize: const <int>[150, 150],
68+
gridThumbSize: 80,
6969
);
7070
},
7171
),

lib/src/constants/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Constants {
4545
DefaultAssetsPickerTextDelegate();
4646
static SortPathDelegate sortPathDelegate = SortPathDelegate.common;
4747

48-
static const List<int> defaultPreviewThumbSize = <int>[200, 200];
48+
static const int defaultGridThumbSize = 200;
4949
}
5050

5151
/// Log only in debug mode.

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ class DefaultAssetPickerBuilderDelegate
421421
WidgetBuilder? specialItemBuilder,
422422
IndicatorBuilder? loadingIndicatorBuilder,
423423
bool allowSpecialItemWhenEmpty = false,
424+
this.gridThumbSize = Constants.defaultGridThumbSize,
424425
this.previewThumbSize,
425426
this.specialPickerType,
426427
}) : assert(
@@ -439,13 +440,25 @@ class DefaultAssetPickerBuilderDelegate
439440
allowSpecialItemWhenEmpty: allowSpecialItemWhenEmpty,
440441
);
441442

443+
/// Thumbnail size in the grid.
444+
/// 预览时网络的缩略图大小
445+
///
446+
/// This only works on images and videos since other types does not have to
447+
/// request for the thumbnail data. The preview can speed up by reducing it.
448+
/// 该参数仅生效于图片和视频类型的资源,因为其他资源不需要请求缩略图数据。
449+
/// 预览图片的速度可以通过适当降低它的数值来提升。
450+
///
451+
/// This cannot be `null` or a large value since you shouldn't use the
452+
/// original data for the grid.
453+
/// 该值不能为空或者非常大,因为在网格中使用原数据不是一个好的决定。
454+
final int gridThumbSize;
455+
442456
/// Preview thumbnail size in the viewer.
443457
/// 预览时图片的缩略图大小
444458
///
445-
/// This only works on images since other types does not have request
446-
/// for thumb data. The speed of preview can be raised by reducing it.
447-
///
448-
/// 该参数仅生效于图片类型的资源,因为其他资源不需要请求缩略图数据。
459+
/// This only works on images and videos since other types does not have to
460+
/// request for the thumbnail data. The preview can speed up by reducing it.
461+
/// 该参数仅生效于图片和视频类型的资源,因为其他资源不需要请求缩略图数据。
449462
/// 预览图片的速度可以通过适当降低它的数值来提升。
450463
///
451464
/// Default is `null`, which will request the origin data.
@@ -802,8 +815,11 @@ class DefaultAssetPickerBuilderDelegate
802815
int index,
803816
AssetEntity asset,
804817
) {
805-
final AssetEntityImageProvider imageProvider =
806-
AssetEntityImageProvider(asset, isOriginal: false);
818+
final AssetEntityImageProvider imageProvider = AssetEntityImageProvider(
819+
asset,
820+
isOriginal: false,
821+
thumbSize: <int>[gridThumbSize, gridThumbSize],
822+
);
807823
return RepaintBoundary(
808824
child: ExtendedImage(
809825
image: imageProvider,

lib/src/delegates/asset_picker_viewer_builder_delegate.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ class DefaultAssetPickerViewerBuilderDelegate
369369
child: ExtendedImage(
370370
image: AssetEntityImageProvider(
371371
asset,
372-
isOriginal: false,
372+
isOriginal: previewThumbSize == null,
373+
thumbSize: previewThumbSize,
373374
),
374375
fit: BoxFit.cover,
375376
),

lib/src/provider/asset_entity_image_provider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AssetEntityImageProvider extends ImageProvider<AssetEntityImageProvider> {
1414
const AssetEntityImageProvider(
1515
this.entity, {
1616
this.scale = 1.0,
17-
this.thumbSize = Constants.defaultPreviewThumbSize,
17+
this.thumbSize,
1818
this.isOriginal = true,
1919
}) : assert(
2020
isOriginal || thumbSize?.length == 2,

lib/src/widget/asset_picker.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class AssetPicker<A, P> extends StatelessWidget {
2424
List<AssetEntity>? selectedAssets,
2525
int maxAssets = 9,
2626
int pageSize = 80,
27+
int gridThumbSize = Constants.defaultGridThumbSize,
2728
int pathThumbSize = 80,
2829
int gridCount = 4,
2930
RequestType requestType = RequestType.image,
@@ -95,6 +96,7 @@ class AssetPicker<A, P> extends StatelessWidget {
9596
textDelegate: textDelegate,
9697
themeColor: themeColor,
9798
pickerTheme: pickerTheme,
99+
gridThumbSize: gridThumbSize,
98100
previewThumbSize: previewThumbSize,
99101
specialPickerType: specialPickerType,
100102
specialItemPosition: specialItemPosition,

0 commit comments

Comments
 (0)