Skip to content

Commit

Permalink
⚡ Improve assets viewing (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Jul 29, 2024
1 parent f0a65eb commit a28392a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ that can be found in the LICENSE file. -->
> [!IMPORTANT]
> See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions.
## Unreleased

### Fixes

- Raise detailed negative range error.
- Fix viewer confirm button predication.
- Enlarge GIF gradients.
- Fix potential paths assets count unexpected merging behaviors.

## 9.1.0

### Improvements
Expand Down
6 changes: 3 additions & 3 deletions lib/src/delegates/asset_picker_builder_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,10 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
/// GIF image type indicator.
/// GIF 类型图片指示
Widget gifIndicator(BuildContext context, Asset asset) {
return PositionedDirectional(
start: 0,
bottom: 0,
return Positioned.fill(
top: null,
child: Container(
alignment: AlignmentDirectional.centerEnd,
padding: const EdgeInsets.all(6),
decoration: BoxDecoration(
gradient: LinearGradient(
Expand Down
25 changes: 19 additions & 6 deletions lib/src/delegates/asset_picker_viewer_builder_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -814,10 +814,9 @@ class DefaultAssetPickerViewerBuilderDelegate
return textDelegate.confirm;
}

final bool isButtonEnabled = provider == null ||
provider.currentlySelectedAssets.isNotEmpty ||
final isButtonEnabled = provider == null ||
previewAssets.isEmpty ||
selectedNotifier.value == 0;
(selectedAssets?.isNotEmpty ?? false);
return MaterialButton(
minWidth:
(isWeChatMoment && hasVideo) || provider!.isSelectedNotEmpty
Expand Down Expand Up @@ -920,9 +919,23 @@ class DefaultAssetPickerViewerBuilderDelegate
stream: pageStreamController.stream,
builder: (_, s) {
final index = s.data!;
final AssetEntity asset = previewAssets.elementAt(
shouldReversePreview ? previewAssets.length - index - 1 : index,
);
final assetIndex =
shouldReversePreview ? previewAssets.length - index - 1 : index;
if (assetIndex < 0) {
throw IndexError.withLength(
assetIndex,
previewAssets.length,
indexable: previewAssets,
name: 'selectButton.assetIndex',
message: 'previewReversed: $shouldReversePreview\n'
'stream.index: $index\n'
'selectedAssets.length: ${selectedAssets?.length}\n'
'previewAssets.length: ${previewAssets.length}\n'
'currentIndex: $currentIndex\n'
'maxAssets: $maxAssets',
);
}
final asset = previewAssets.elementAt(assetIndex);
return Selector<AssetPickerViewerProvider<AssetEntity>,
List<AssetEntity>>(
selector: (_, p) => p.currentlySelectedAssets,
Expand Down
16 changes: 11 additions & 5 deletions lib/src/provider/asset_picker_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,13 @@ class DefaultAssetPickerProvider
_paths = list.map((p) => PathWrapper<AssetPathEntity>(path: p)).toList();
// Sort path using sort path delegate.
Singleton.sortPathDelegate.sort(_paths);
// Use sync method to avoid unnecessary wait.
_paths
..forEach(getAssetCountFromPath)
..forEach(getThumbnailFromPath);
// Populate fields to paths without awaiting.
for (final path in _paths) {
Future(() async {
await getAssetCountFromPath(path);
await getThumbnailFromPath(path);
});
}

// Set first path entity as current path entity.
if (_paths.isNotEmpty) {
Expand Down Expand Up @@ -479,7 +482,10 @@ class DefaultAssetPickerProvider
(PathWrapper<AssetPathEntity> p) => p.path == path.path,
);
if (index != -1) {
_paths[index] = _paths[index].copyWith(thumbnailData: data);
_paths[index] = _paths[index].copyWith(
assetCount: assetCount,
thumbnailData: data,
);
notifyListeners();
}
return data;
Expand Down

0 comments on commit a28392a

Please sign in to comment.