Skip to content

Commit 5e6126b

Browse files
authored
✨ First 6.0 version
2 parents d683fcf + 3235b7b commit 5e6126b

20 files changed

+1456
-573
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## 6.0.0-dev.1
8+
9+
Sync everything with WeChat 8.x .
10+
11+
### New features
12+
13+
- Change the permission from the app settings when it's limited.
14+
- Request more assets on iOS when the permission is limited.
15+
- Fit the assets' grid's layout as the iOS `Photos` app (reverted and start from the bottom).
16+
- Add Arabic language text delegate.
17+
- Allow using `AssetPicker` and `AssetPickerViewer` directly with delegates.
18+
19+
### Improvements
20+
21+
- Items that being banned from select (reached max assets or type conflict)
22+
will have a stronger color cover to indicate.
23+
- Video preview in the [SpecialPickerType.wechatMoment] is completely different from other previews.
24+
- Grid items has removed fade builder for more straight feedback after it gets loaded.
25+
- Better interaction when jumping between previewing assets.
26+
- Path entities list layout structure performance & structure improved.
27+
- More precise thumbnail's option for iOS.
28+
29+
### Breaking changes
30+
31+
Multiple refactoring happened with delegates,
32+
see [Migration Guide](guides/migration_guide.md) for more details.
33+
734
## 5.5.7
835

936
- Make `switchPath` method in `AssetPickerProvider` async.

example/lib/customs/pickers/directory_file_asset_picker.dart

Lines changed: 136 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -369,23 +369,25 @@ class FileAssetPickerProvider extends AssetPickerProvider<File, Directory> {
369369
}
370370

371371
@override
372-
void switchPath(Directory pathEntity) {
372+
Future<void> switchPath([Directory? pathEntity]) async {
373+
if (pathEntity == null) {
374+
return;
375+
}
373376
isSwitchingPath = false;
374377
currentPathEntity = pathEntity;
375378
totalAssetsCount = 0;
376379
notifyListeners();
377-
getAssetsFromEntity(0, currentPathEntity!);
380+
await getAssetsFromEntity(0, currentPathEntity!);
378381
}
379382
}
380383

381384
class FileAssetPickerBuilder
382385
extends AssetPickerBuilderDelegate<File, Directory> {
383386
FileAssetPickerBuilder({
384387
required FileAssetPickerProvider provider,
385-
}) : super(provider: provider);
388+
}) : super(provider: provider, initialPermission: PermissionState.authorized);
386389

387-
AssetsPickerTextDelegate get textDelegate =>
388-
DefaultAssetsPickerTextDelegate();
390+
AssetsPickerTextDelegate get textDelegate => AssetsPickerTextDelegate();
389391

390392
Duration get switchingPathDuration => kThemeAnimationDuration * 1.5;
391393

@@ -533,6 +535,120 @@ class FileAssetPickerBuilder
533535
);
534536
}
535537

538+
@override
539+
Widget assetsGridBuilder(BuildContext context) {
540+
int totalCount = provider.currentAssets.length;
541+
if (specialItemPosition != SpecialItemPosition.none) {
542+
totalCount += 1;
543+
}
544+
final int placeholderCount;
545+
if (isAppleOS && totalCount % gridCount != 0) {
546+
placeholderCount = gridCount - totalCount % gridCount;
547+
} else {
548+
placeholderCount = 0;
549+
}
550+
final int row = (totalCount + placeholderCount) ~/ gridCount;
551+
final double dividedSpacing = itemSpacing / gridCount;
552+
final double topPadding =
553+
MediaQuery.of(context).padding.top + kToolbarHeight;
554+
555+
Widget _sliverGrid(BuildContext ctx, List<File> assets) {
556+
return SliverGrid(
557+
delegate: SliverChildBuilderDelegate(
558+
(_, int index) => Builder(
559+
builder: (BuildContext c) {
560+
if (isAppleOS) {
561+
if (index < placeholderCount) {
562+
return const SizedBox.shrink();
563+
}
564+
index -= placeholderCount;
565+
}
566+
return Directionality(
567+
textDirection: Directionality.of(context),
568+
child: assetGridItemBuilder(c, index, assets),
569+
);
570+
},
571+
),
572+
childCount: assetsGridItemCount(
573+
context: ctx,
574+
assets: assets,
575+
placeholderCount: placeholderCount,
576+
),
577+
findChildIndexCallback: (Key? key) {
578+
if (key is ValueKey<String>) {
579+
return findChildIndexBuilder(
580+
id: key.value,
581+
assets: assets,
582+
placeholderCount: placeholderCount,
583+
);
584+
}
585+
return null;
586+
},
587+
),
588+
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
589+
crossAxisCount: gridCount,
590+
mainAxisSpacing: itemSpacing,
591+
crossAxisSpacing: itemSpacing,
592+
),
593+
);
594+
}
595+
596+
return LayoutBuilder(
597+
builder: (BuildContext c, BoxConstraints constraints) {
598+
final double _itemSize = constraints.maxWidth / gridCount;
599+
// Use [ScrollView.anchor] to determine where is the first place of
600+
// the [SliverGrid]. Each row needs [dividedSpacing] to calculate,
601+
// then minus one times of [itemSpacing] because spacing's count in the
602+
// cross axis is always less than the rows.
603+
final double anchor = math.min(
604+
(row * (_itemSize + dividedSpacing) + topPadding - itemSpacing) /
605+
constraints.maxHeight,
606+
1,
607+
);
608+
609+
return Directionality(
610+
textDirection: effectiveGridDirection(context),
611+
child: ColoredBox(
612+
color: theme.canvasColor,
613+
child: Selector<FileAssetPickerProvider, List<File>>(
614+
selector: (_, FileAssetPickerProvider provider) =>
615+
provider.currentAssets,
616+
builder: (_, List<File> assets, __) => CustomScrollView(
617+
physics: const AlwaysScrollableScrollPhysics(),
618+
controller: gridScrollController,
619+
anchor: isAppleOS ? anchor : 0,
620+
center: isAppleOS ? gridRevertKey : null,
621+
slivers: <Widget>[
622+
if (isAppleOS)
623+
SliverToBoxAdapter(
624+
child: SizedBox(
625+
height:
626+
MediaQuery.of(context).padding.top + kToolbarHeight,
627+
),
628+
),
629+
_sliverGrid(_, assets),
630+
// Ignore the gap when the [anchor] is not equal to 1.
631+
if (isAppleOS && anchor == 1)
632+
SliverToBoxAdapter(
633+
child: SizedBox(
634+
height: MediaQuery.of(context).padding.bottom +
635+
bottomSectionHeight,
636+
),
637+
),
638+
if (isAppleOS)
639+
SliverToBoxAdapter(
640+
key: gridRevertKey,
641+
child: const SizedBox.shrink(),
642+
),
643+
],
644+
),
645+
),
646+
),
647+
);
648+
},
649+
);
650+
}
651+
536652
@override
537653
Widget assetGridItemBuilder(
538654
BuildContext context,
@@ -567,18 +683,22 @@ class FileAssetPickerBuilder
567683
}
568684

569685
@override
570-
int assetsGridItemCount(BuildContext context, List<File> currentAssets) {
686+
int assetsGridItemCount({
687+
required BuildContext context,
688+
required List<File> assets,
689+
int placeholderCount = 0,
690+
}) {
571691
int length;
572692
switch (specialItemPosition) {
573693
case SpecialItemPosition.none:
574-
length = currentAssets.length;
694+
length = assets.length;
575695
break;
576696
case SpecialItemPosition.prepend:
577697
case SpecialItemPosition.append:
578-
length = currentAssets.length + 1;
698+
length = assets.length + 1;
579699
break;
580700
}
581-
return length;
701+
return length + placeholderCount;
582702
}
583703

584704
@override
@@ -1047,8 +1167,12 @@ class FileAssetPickerBuilder
10471167
}
10481168

10491169
@override
1050-
int findChildIndexBuilder(String id, List<File> currentAssets) {
1051-
return currentAssets.indexWhere((File file) => file.path == id);
1170+
int findChildIndexBuilder({
1171+
required String id,
1172+
required List<File> assets,
1173+
int placeholderCount = 0,
1174+
}) {
1175+
return assets.indexWhere((File file) => file.path == id);
10521176
}
10531177
}
10541178

@@ -1091,8 +1215,7 @@ class FileAssetPickerViewerBuilderDelegate
10911215

10921216
late final PageController pageController;
10931217

1094-
AssetsPickerTextDelegate get textDelegate =>
1095-
DefaultAssetsPickerTextDelegate();
1218+
AssetsPickerTextDelegate get textDelegate => AssetsPickerTextDelegate();
10961219

10971220
void switchDisplayingDetail({bool? value}) {
10981221
isDisplayingDetail = value ?? !isDisplayingDetail;

guides/migration_guide.md

Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,96 @@
11
# Migration Guide
22

3-
## Migrate to 5.0.0
3+
This document gathered all breaking changes and migrations requirement between major versions.
4+
5+
## References
6+
7+
API documentation:
8+
- `AssetPickerBuilderDelegate`:
9+
- https://pub.dev/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetPickerBuilderDelegate-class.html
10+
- https://pub.flutter-io.cn/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetPickerBuilderDelegate-class.html
11+
- `AssetPickerViewerBuilderDelegate`:
12+
- https://pub.dev/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetPickerViewerBuilderDelegate-class.html
13+
- https://pub.flutter-io.cn/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetPickerViewerBuilderDelegate-class.html
14+
- `AssetPickerProvider`:
15+
- https://pub.dev/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetPickerProvider-class.html
16+
- https://pub.flutter-io.cn/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetPickerProvider-class.html
17+
- `AssetPickerViewerProvider`:
18+
- https://pub.dev/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetPickerViewerProvider-class.html
19+
- https://pub.flutter-io.cn/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetPickerViewerProvider-class.html
20+
- `AssetsPickerTextDelegate`:
21+
- https://pub.dev/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetsPickerTextDelegate-class.html
22+
- https://pub.flutter-io.cn/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetsPickerTextDelegate-class.html
23+
24+
## Major versions
25+
26+
- [6.0.0](#6.0.0)
27+
- [5.0.0](#5.0.0)
28+
29+
## 6.0.0
30+
31+
### Summary
32+
33+
_If you didn't extend `AssetPickerBuilderDelegate` or `AssetTextDelegate` to build delegates on your own,
34+
you can stop reading._
35+
36+
- User who extended `AssetPickerBuilderDelegate` needs to update the subclass with the latest changes.
37+
- `AssetsPickerTextDelegate` is not abstract anymore.
38+
39+
### Details
40+
41+
#### `AssetPickerBuilderDelegate`
42+
43+
- This delegate requires a new argument `initialPermission` with `PermissionState` type when using.
44+
The intention of this change is to be capable with various of `PermissionState`.
45+
If your delegate didn't require a permission check, you can pass `PermissionState.authorized` directly.
46+
47+
- `assetsGridBuilder` is not implemented by default.
48+
49+
- The `findChildIndexBuilder` and `assetsGridItemCount` methods have new signature.
50+
They require calculating placeholders count on iOS/macOS by default.
51+
52+
#### `AssetsPickerTextDelegate`
53+
54+
- This delegate is now a normal class with Chinese language implemented by default,
55+
which makes `DefaultAssetsPickerTextDelegate` removed. So if you used to use `DefaultAssetsPickerTextDelegate()`,
56+
use `AssetsPickerTextDelegate()` instead.
57+
58+
#### `AssetPickerProvider`
59+
60+
- The `switchPath` method has a different signature:
61+
62+
Before:
63+
64+
```dart
65+
void switchPath(P pathEntity);
66+
```
67+
68+
After:
69+
70+
```dart
71+
Future<void> switchPath([P? pathEntity]);
72+
```
73+
74+
## 5.0.0
475

576
### Summary
677

778
_If you only use the `AssetPicker.pickAssets` and `AssetEntityImageProvider`,
879
didn't use `AssetPickerViewer`, `AssetPickerProvider`, or other components separately,
980
you can stop reading._
1081

11-
`AssetPicker` and `AssetPickerViewer` are only a builder since 5.x, all widgets construct were moved
12-
to `AssetPickerBuilderDelegate` and `AssetPickerViewerBuilderDelegate`, and these delegates are both
13-
abstract.
82+
The `AssetPicker` and the `AssetPickerViewer` are only a builder since 5.x,
83+
all widgets construct were moved to `AssetPickerBuilderDelegate` and `AssetPickerViewerBuilderDelegate`,
84+
and these delegates are both abstract.
1485

1586
By splitting delegates, now you can build your own picker with custom types, style, and widgets.
1687

17-
### Migration steps
88+
#### Details
1889

1990
For how to implement a custom picker, see the example's custom page for more implementation details.
2091

21-
* If you have ever use `AssetPickerViewer.pushToViewer`, the properties `assets` has changed to
92+
- If you have ever use `AssetPickerViewer.pushToViewer`, the properties `assets` has changed to
2293
`previewAssets`.
2394

24-
* If you have extends an `AssetPickerProvider` or `AssetPickerViewerProvider`, it now requires you
95+
- If you have extended an `AssetPickerProvider` or `AssetPickerViewerProvider`, it now requires you
2596
to pass generic type `A` and `P`, and handle the entities on your own.
26-
27-
### References
28-
29-
API documentation:
30-
* `AssetPickerBuilderDelegate`: https://pub.dev/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetPickerBuilderDelegate-class.html
31-
* `AssetPickerViewerBuilderDelegate`: https://pub.dev/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetPickerViewerBuilderDelegate-class.html
32-
* `AssetPickerProvider`: https://pub.dev/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetPickerProvider-class.html
33-
* `AssetPickerViewerProvider`: https://pub.dev/documentation/wechat_assets_picker/latest/wechat_assets_picker/AssetPickerViewerProvider-class.html

lib/src/constants/constants.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,20 @@ export '../widget/builder/fade_image_builder.dart';
2828
export '../widget/builder/image_page_builder.dart';
2929
export '../widget/builder/video_page_builder.dart';
3030
export '../widget/fixed_appbar.dart';
31+
export '../widget/gaps.dart';
3132
export '../widget/platform_progress_indicator.dart';
3233

3334
export 'colors.dart';
3435
export 'custom_scroll_physics.dart';
3536
export 'enums.dart';
3637
export 'extensions.dart';
37-
export 'screens.dart';
3838

3939
class Constants {
4040
const Constants._();
4141

4242
static GlobalKey pickerKey = GlobalKey();
4343

44-
static AssetsPickerTextDelegate textDelegate =
45-
DefaultAssetsPickerTextDelegate();
44+
static AssetsPickerTextDelegate textDelegate = AssetsPickerTextDelegate();
4645
static SortPathDelegate sortPathDelegate = SortPathDelegate.common;
4746

4847
static const int defaultGridThumbSize = 200;

lib/src/constants/extensions.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ extension BuildContextExtension on BuildContext {
88
MediaQueryData get mediaQuery => MediaQuery.of(this);
99

1010
ThemeData get themeData => Theme.of(this);
11+
12+
double get topPadding => mediaQuery.padding.top;
13+
14+
double get bottomPadding => mediaQuery.padding.bottom;
15+
16+
double get bottomInsets => mediaQuery.viewInsets.bottom;
1117
}
1218

1319
extension BrightnessExtension on Brightness {
@@ -17,7 +23,7 @@ extension BrightnessExtension on Brightness {
1723
}
1824

1925
extension ColorExtension on Color {
20-
bool get isTransparent => this == Colors.transparent;
26+
bool get isTransparent => this == Colors.transparent || alpha == 0x00;
2127
}
2228

2329
extension ThemeDataExtension on ThemeData {

0 commit comments

Comments
 (0)