Skip to content

Commit a28392a

Browse files
authored
⚡ Improve assets viewing (#605)
1 parent f0a65eb commit a28392a

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ that can be found in the LICENSE file. -->
77
> [!IMPORTANT]
88
> See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions.
99
10+
## Unreleased
11+
12+
### Fixes
13+
14+
- Raise detailed negative range error.
15+
- Fix viewer confirm button predication.
16+
- Enlarge GIF gradients.
17+
- Fix potential paths assets count unexpected merging behaviors.
18+
1019
## 9.1.0
1120

1221
### Improvements

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,10 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
389389
/// GIF image type indicator.
390390
/// GIF 类型图片指示
391391
Widget gifIndicator(BuildContext context, Asset asset) {
392-
return PositionedDirectional(
393-
start: 0,
394-
bottom: 0,
392+
return Positioned.fill(
393+
top: null,
395394
child: Container(
395+
alignment: AlignmentDirectional.centerEnd,
396396
padding: const EdgeInsets.all(6),
397397
decoration: BoxDecoration(
398398
gradient: LinearGradient(

lib/src/delegates/asset_picker_viewer_builder_delegate.dart

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,9 @@ class DefaultAssetPickerViewerBuilderDelegate
814814
return textDelegate.confirm;
815815
}
816816

817-
final bool isButtonEnabled = provider == null ||
818-
provider.currentlySelectedAssets.isNotEmpty ||
817+
final isButtonEnabled = provider == null ||
819818
previewAssets.isEmpty ||
820-
selectedNotifier.value == 0;
819+
(selectedAssets?.isNotEmpty ?? false);
821820
return MaterialButton(
822821
minWidth:
823822
(isWeChatMoment && hasVideo) || provider!.isSelectedNotEmpty
@@ -920,9 +919,23 @@ class DefaultAssetPickerViewerBuilderDelegate
920919
stream: pageStreamController.stream,
921920
builder: (_, s) {
922921
final index = s.data!;
923-
final AssetEntity asset = previewAssets.elementAt(
924-
shouldReversePreview ? previewAssets.length - index - 1 : index,
925-
);
922+
final assetIndex =
923+
shouldReversePreview ? previewAssets.length - index - 1 : index;
924+
if (assetIndex < 0) {
925+
throw IndexError.withLength(
926+
assetIndex,
927+
previewAssets.length,
928+
indexable: previewAssets,
929+
name: 'selectButton.assetIndex',
930+
message: 'previewReversed: $shouldReversePreview\n'
931+
'stream.index: $index\n'
932+
'selectedAssets.length: ${selectedAssets?.length}\n'
933+
'previewAssets.length: ${previewAssets.length}\n'
934+
'currentIndex: $currentIndex\n'
935+
'maxAssets: $maxAssets',
936+
);
937+
}
938+
final asset = previewAssets.elementAt(assetIndex);
926939
return Selector<AssetPickerViewerProvider<AssetEntity>,
927940
List<AssetEntity>>(
928941
selector: (_, p) => p.currentlySelectedAssets,

lib/src/provider/asset_picker_provider.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,13 @@ class DefaultAssetPickerProvider
365365
_paths = list.map((p) => PathWrapper<AssetPathEntity>(path: p)).toList();
366366
// Sort path using sort path delegate.
367367
Singleton.sortPathDelegate.sort(_paths);
368-
// Use sync method to avoid unnecessary wait.
369-
_paths
370-
..forEach(getAssetCountFromPath)
371-
..forEach(getThumbnailFromPath);
368+
// Populate fields to paths without awaiting.
369+
for (final path in _paths) {
370+
Future(() async {
371+
await getAssetCountFromPath(path);
372+
await getThumbnailFromPath(path);
373+
});
374+
}
372375

373376
// Set first path entity as current path entity.
374377
if (_paths.isNotEmpty) {
@@ -479,7 +482,10 @@ class DefaultAssetPickerProvider
479482
(PathWrapper<AssetPathEntity> p) => p.path == path.path,
480483
);
481484
if (index != -1) {
482-
_paths[index] = _paths[index].copyWith(thumbnailData: data);
485+
_paths[index] = _paths[index].copyWith(
486+
assetCount: assetCount,
487+
thumbnailData: data,
488+
);
483489
notifyListeners();
484490
}
485491
return data;

0 commit comments

Comments
 (0)