Skip to content

Commit 1c98ad5

Browse files
authored
⚡️ Several improvements (#359)
* ⚡️ Improve context usages * ⚡️ Better condition for confirm button * ♻️ `bottomActionBar` requires implementation * ⏪️ Reset `bottomActionBar` * 🔖 8.0.3
1 parent 686fd09 commit 1c98ad5

File tree

6 files changed

+32
-27
lines changed

6 files changed

+32
-27
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ that can be found in the LICENSE file. -->
44

55
# Changelog
66

7+
## 8.0.3
8+
9+
### Improvements
10+
11+
- Improve `BuildContext` usages to obtain the correct directionality for the assets grid. (359)
12+
- Provide a better condition to the confirm button
13+
to make sure it displays correctly in all cases on iOS/macOS. (359)
14+
- Improve `bottomActionBar` in `DefaultAssetPickerBuilderDelegate`. (359)
15+
716
## 8.0.2
817

918
### Improvements

example/lib/customs/pickers/directory_file_asset_picker.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ class FileAssetPickerProvider extends AssetPickerProvider<File, Directory> {
332332
}
333333

334334
@override
335-
Future<typed_data.Uint8List?> getThumbnailFromPath(PathWrapper<Directory> path) async {
335+
Future<typed_data.Uint8List?> getThumbnailFromPath(
336+
PathWrapper<Directory> path,
337+
) async {
336338
final List<FileSystemEntity> entities =
337339
path.path.listSync().whereType<File>().toList();
338340
currentAssets.clear();
@@ -460,8 +462,7 @@ class FileAssetPickerBuilder
460462
child: Column(
461463
children: <Widget>[
462464
Expanded(child: assetsGridBuilder(context)),
463-
if (!isSingleAssetMode)
464-
bottomActionBar(context),
465+
if (!isAppleOS) bottomActionBar(context),
465466
],
466467
),
467468
),

example/lib/customs/pickers/multi_tabs_assets_picker.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,7 @@ class MultiTabAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
452452
child: pathEntitySelector(context),
453453
),
454454
leading: backButton(context),
455-
actions: (isPreviewEnabled || !isSingleAssetMode)
456-
? <Widget>[confirmButton(context)]
457-
: null,
455+
actions: <Widget>[if (!isAppleOS) confirmButton(context)],
458456
actionsPadding: const EdgeInsetsDirectional.only(end: 14),
459457
blurRadius: isAppleOS ? appleOSBlurRadius : 0,
460458
bottom: TabBar(
@@ -508,7 +506,7 @@ class MultiTabAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
508506
child: Column(
509507
children: <Widget>[
510508
Expanded(child: assetsGridBuilder(context)),
511-
if (!isSingleAssetMode && isPreviewEnabled)
509+
if (isPreviewEnabled)
512510
bottomActionBar(context),
513511
],
514512
),

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: wechat_assets_picker_demo
22
description: The demo project for the wechat_assets_picker package.
3-
version: 8.0.2+23
3+
version: 8.0.3+24
44
publish_to: none
55

66
environment:

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
512512
color: theme.primaryColor.withOpacity(isAppleOS ? 0.90 : 1),
513513
child: Row(
514514
children: <Widget>[
515-
if (!isSingleAssetMode || !isAppleOS) previewButton(context),
515+
if (!isAppleOS) previewButton(context),
516516
if (isAppleOS) const Spacer(),
517517
if (isAppleOS) confirmButton(context),
518518
],
@@ -898,11 +898,8 @@ class DefaultAssetPickerBuilderDelegate
898898
// - On Android, show if preview is enabled or if multi asset mode.
899899
// If no preview and single asset mode, do not show confirm button,
900900
// because any click on an asset selects it.
901-
// - On iOS, show if no preview and multi asset mode. This is because for iOS
902-
// the [bottomActionBar] has the confirm button, but if no preview,
903-
// [bottomActionBar] is not displayed.
904-
actions: (!isAppleOS || !isPreviewEnabled) &&
905-
(isPreviewEnabled || !isSingleAssetMode)
901+
// - On iOS and macOS, show nothing.
902+
actions: !isAppleOS && !isSingleAssetMode
906903
? <Widget>[confirmButton(context)]
907904
: null,
908905
actionsPadding: const EdgeInsetsDirectional.only(end: 14),
@@ -954,7 +951,7 @@ class DefaultAssetPickerBuilderDelegate
954951
child: Stack(
955952
children: <Widget>[
956953
Positioned.fill(child: assetsGridBuilder(context)),
957-
if ((!isSingleAssetMode || isAppleOS) && isPreviewEnabled)
954+
if (!isSingleAssetMode || isAppleOS)
958955
Positioned.fill(
959956
top: null,
960957
child: bottomActionBar(context),
@@ -1032,7 +1029,7 @@ class DefaultAssetPickerBuilderDelegate
10321029
return Selector<DefaultAssetPickerProvider, PathWrapper<AssetPathEntity>?>(
10331030
selector: (_, DefaultAssetPickerProvider p) => p.currentPath,
10341031
builder: (
1035-
BuildContext context,
1032+
BuildContext _context,
10361033
PathWrapper<AssetPathEntity>? wrapper,
10371034
__,
10381035
) {
@@ -1042,7 +1039,7 @@ class DefaultAssetPickerBuilderDelegate
10421039
// If user chose a special item's position, add 1 count.
10431040
if (specialItemPosition != SpecialItemPosition.none) {
10441041
specialItem = specialItemBuilder?.call(
1045-
context,
1042+
_context,
10461043
wrapper?.path,
10471044
totalCount,
10481045
);
@@ -1053,7 +1050,7 @@ class DefaultAssetPickerBuilderDelegate
10531050
specialItem = null;
10541051
}
10551052
if (totalCount == 0 && specialItem == null) {
1056-
return loadingIndicator(context);
1053+
return loadingIndicator(_context);
10571054
}
10581055
// Then we use the [totalCount] to calculate placeholders we need.
10591056
final int placeholderCount;
@@ -1071,13 +1068,13 @@ class DefaultAssetPickerBuilderDelegate
10711068
// [gridCount] since every grid item is squeezed by the [itemSpacing],
10721069
// and it's actual size is reduced with [itemSpacing / gridCount].
10731070
final double dividedSpacing = itemSpacing / gridCount;
1074-
final double topPadding = context.topPadding + kToolbarHeight;
1071+
final double topPadding = _context.topPadding + kToolbarHeight;
10751072

1076-
Widget _sliverGrid(BuildContext context, List<AssetEntity> assets) {
1073+
Widget _sliverGrid(BuildContext _context, List<AssetEntity> assets) {
10771074
return SliverGrid(
10781075
delegate: SliverChildBuilderDelegate(
10791076
(_, int index) => Builder(
1080-
builder: (BuildContext context) {
1077+
builder: (BuildContext _context) {
10811078
if (effectiveShouldRevertGrid) {
10821079
if (index < placeholderCount) {
10831080
return const SizedBox.shrink();
@@ -1088,7 +1085,7 @@ class DefaultAssetPickerBuilderDelegate
10881085
child: Directionality(
10891086
textDirection: Directionality.of(context),
10901087
child: assetGridItemBuilder(
1091-
context,
1088+
_context,
10921089
index,
10931090
assets,
10941091
specialItem: specialItem,
@@ -1098,7 +1095,7 @@ class DefaultAssetPickerBuilderDelegate
10981095
},
10991096
),
11001097
childCount: assetsGridItemCount(
1101-
context: context,
1098+
context: _context,
11021099
assets: assets,
11031100
placeholderCount: placeholderCount,
11041101
specialItem: specialItem,
@@ -1125,7 +1122,7 @@ class DefaultAssetPickerBuilderDelegate
11251122
}
11261123

11271124
return LayoutBuilder(
1128-
builder: (BuildContext c, BoxConstraints constraints) {
1125+
builder: (BuildContext context, BoxConstraints constraints) {
11291126
final double itemSize = constraints.maxWidth / gridCount;
11301127
// Check whether all rows can be placed at the same time.
11311128
final bool onlyOneScreen = row * itemSize <=
@@ -1157,7 +1154,7 @@ class DefaultAssetPickerBuilderDelegate
11571154
child: Selector<DefaultAssetPickerProvider, List<AssetEntity>>(
11581155
selector: (_, DefaultAssetPickerProvider p) =>
11591156
p.currentAssets,
1160-
builder: (_, List<AssetEntity> assets, __) {
1157+
builder: (BuildContext context, List<AssetEntity> assets, _) {
11611158
final SliverGap bottomGap = SliverGap.v(
11621159
context.bottomPadding + bottomSectionHeight,
11631160
);
@@ -1169,7 +1166,7 @@ class DefaultAssetPickerBuilderDelegate
11691166
slivers: <Widget>[
11701167
if (isAppleOS)
11711168
SliverGap.v(context.topPadding + kToolbarHeight),
1172-
_sliverGrid(_, assets),
1169+
_sliverGrid(context, assets),
11731170
// Ignore the gap when the [anchor] is not equal to 1.
11741171
if (effectiveShouldRevertGrid && anchor == 1) bottomGap,
11751172
if (effectiveShouldRevertGrid)

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: wechat_assets_picker
22
description: An audio/video/image picker in pure Dart which is the same with WeChat, support multi picking.
3-
version: 8.0.2
3+
version: 8.0.3
44
homepage: https://github.com/fluttercandies/flutter_wechat_assets_picker
55

66
environment:

0 commit comments

Comments
 (0)