Skip to content

Commit

Permalink
Revert "✨ Integrate PermissionRequestOption for callers (#517)"
Browse files Browse the repository at this point in the history
This reverts commit b702fd6
  • Loading branch information
AlexV525 committed Dec 28, 2023
1 parent 6292580 commit e0749c9
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 115 deletions.
10 changes: 2 additions & 8 deletions example/lib/customs/pickers/insta_asset_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,8 @@ class _InstaAssetPickerState extends State<InstaAssetPicker> {
}

Future<void> callPicker(BuildContext context) async {
final PermissionState ps = await AssetPicker.permissionCheck(
requestOption: PermissionRequestOption(
androidPermission: AndroidPermission(
type: provider.requestType,
mediaLocation: false,
),
),
);
final PermissionState ps = await AssetPicker.permissionCheck();

final InstaAssetPickerBuilder builder = InstaAssetPickerBuilder(
provider: provider,
initialPermission: ps,
Expand Down
9 changes: 1 addition & 8 deletions example/lib/customs/pickers/multi_tabs_assets_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ class _MultiTabAssetPickerState extends State<MultiTabAssetPicker> {
bool isDisplayingDetail = true;

Future<void> callPicker(BuildContext context) async {
final PermissionState ps = await AssetPicker.permissionCheck(
requestOption: const PermissionRequestOption(
androidPermission: AndroidPermission(
type: RequestType.all,
mediaLocation: false,
),
),
);
final PermissionState ps = await AssetPicker.permissionCheck();

final DefaultAssetPickerProvider provider = DefaultAssetPickerProvider(
selectedAssets: entities,
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: wechat_assets_picker_demo
description: The demo project for the wechat_assets_picker package.
version: 9.0.0+48
version: 8.8.1+48
publish_to: none

environment:
Expand Down
60 changes: 0 additions & 60 deletions guides/migration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ This document gathered all breaking changes and migrations requirement between m

## Major versions

- [9.0.0](#900)
- [8.6.0](#860)
- [8.3.0](#830)
- [8.2.0](#820)
Expand All @@ -17,65 +16,6 @@ This document gathered all breaking changes and migrations requirement between m
- [6.0.0](#600)
- [5.0.0](#500)

## 9.0.0

### Summary

`PermissionRequestOption` has been added to
`AssetPickerDelegate.permissionCheck` and
`AssetPickerDelegate.pickAssetsWithDelegate` as an argument.
Classes that extend `AssetPickerDelegate` and override these methods must migrate,
Delegates that use `AssetPicker.permissionCheck`
should choose whether to pass the request option.

### Details

Before:

1. ```dart
AssetPicker.permissionCheck();
```

2. ```dart
Future<PermissionState> permissionCheck();
```

3. ```dart
Future<List<Asset>?> pickAssetsWithDelegate<Asset, Path,
PickerProvider extends AssetPickerProvider<Asset, Path>>(
BuildContext context, {
required AssetPickerBuilderDelegate<Asset, Path> delegate,
Key? key,
bool useRootNavigator = true,
AssetPickerPageRouteBuilder<List<Asset>>? pageRouteBuilder,
})
```

After:

1. ```dart
AssetPicker.permissionCheck(requestOption: ...);
```

2. ```dart
Future<PermissionState> permissionCheck({
PermissionRequestOption requestOption = const PermissionRequestOption,
});
```

3. ```dart
Future<List<Asset>?> pickAssetsWithDelegate<Asset, Path,
PickerProvider extends AssetPickerProvider<Asset, Path>>(
BuildContext context, {
required AssetPickerBuilderDelegate<Asset, Path> delegate,
PermissionRequestOption requestOption =
const PermissionRequestOption,
Key? key,
bool useRootNavigator = true,
AssetPickerPageRouteBuilder<List<Asset>>? pageRouteBuilder,
})
```

## 8.6.0

### Summary
Expand Down
21 changes: 4 additions & 17 deletions lib/src/delegates/asset_picker_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ class AssetPickerDelegate {
/// See also:
/// * [PermissionState] which defined all states of required permissions.
/// {@endtemplate}
Future<PermissionState> permissionCheck({
PermissionRequestOption requestOption = const PermissionRequestOption(),
}) async {
final PermissionState ps = await PhotoManager.requestPermissionExtend(
requestOption: requestOption,
);
Future<PermissionState> permissionCheck() async {
final PermissionState ps = await PhotoManager.requestPermissionExtend();
if (ps != PermissionState.authorized && ps != PermissionState.limited) {
throw StateError('Permission state error with $ps.');
}
Expand Down Expand Up @@ -68,14 +64,7 @@ class AssetPickerDelegate {
bool useRootNavigator = true,
AssetPickerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
}) async {
final PermissionState ps = await permissionCheck(
requestOption: PermissionRequestOption(
androidPermission: AndroidPermission(
type: pickerConfig.requestType,
mediaLocation: false,
),
),
);
final PermissionState ps = await permissionCheck();
final AssetPickerPageRoute<List<AssetEntity>> route =
pageRouteBuilder?.call(const SizedBox.shrink()) ??
AssetPickerPageRoute<List<AssetEntity>>(
Expand Down Expand Up @@ -145,13 +134,11 @@ class AssetPickerDelegate {
PickerProvider extends AssetPickerProvider<Asset, Path>>(
BuildContext context, {
required AssetPickerBuilderDelegate<Asset, Path> delegate,
PermissionRequestOption permissionRequestOption =
const PermissionRequestOption(),
Key? key,
bool useRootNavigator = true,
AssetPickerPageRouteBuilder<List<Asset>>? pageRouteBuilder,
}) async {
await permissionCheck(requestOption: permissionRequestOption);
await permissionCheck();
final Widget picker = AssetPicker<Asset, Path>(
key: key,
builder: delegate,
Expand Down
6 changes: 2 additions & 4 deletions lib/src/widget/asset_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ class AssetPicker<Asset, Path> extends StatefulWidget {
}

/// {@macro wechat_assets_picker.delegates.AssetPickerDelegate.permissionCheck}
static Future<PermissionState> permissionCheck({
PermissionRequestOption requestOption = const PermissionRequestOption(),
}) {
return _pickerDelegate.permissionCheck(requestOption: requestOption);
static Future<PermissionState> permissionCheck() {
return _pickerDelegate.permissionCheck();
}

/// {@macro wechat_assets_picker.delegates.AssetPickerDelegate.pickAssets}
Expand Down
8 changes: 2 additions & 6 deletions lib/src/widget/asset_picker_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ class AssetPickerViewer<Asset, Path> extends StatefulWidget {
int? maxAssets,
bool shouldReversePreview = false,
AssetSelectPredicate<AssetEntity>? selectPredicate,
PermissionRequestOption permissionRequestOption =
const PermissionRequestOption(),
}) async {
await AssetPicker.permissionCheck(requestOption: permissionRequestOption);
await AssetPicker.permissionCheck();
final Widget viewer = AssetPickerViewer<AssetEntity, AssetPathEntity>(
builder: DefaultAssetPickerViewerBuilderDelegate(
currentIndex: currentIndex,
Expand Down Expand Up @@ -84,10 +82,8 @@ class AssetPickerViewer<Asset, Path> extends StatefulWidget {
static Future<List<A>?> pushToViewerWithDelegate<A, P>(
BuildContext context, {
required AssetPickerViewerBuilderDelegate<A, P> delegate,
PermissionRequestOption permissionRequestOption =
const PermissionRequestOption(),
}) async {
await AssetPicker.permissionCheck(requestOption: permissionRequestOption);
await AssetPicker.permissionCheck();
final Widget viewer = AssetPickerViewer<A, P>(builder: delegate);
final PageRouteBuilder<List<A>> pageRoute = PageRouteBuilder<List<A>>(
pageBuilder: (_, __, ___) => viewer,
Expand Down
13 changes: 2 additions & 11 deletions test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ class TestPhotoManagerPlugin extends PhotoManagerPlugin {

class TestAssetPickerDelegate extends AssetPickerDelegate {
@override
Future<PermissionState> permissionCheck({
PermissionRequestOption requestOption = const PermissionRequestOption(),
}) async {
Future<PermissionState> permissionCheck() async {
return SynchronousFuture<PermissionState>(PermissionState.authorized);
}

Expand All @@ -87,14 +85,7 @@ class TestAssetPickerDelegate extends AssetPickerDelegate {
bool useRootNavigator = true,
AssetPickerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
}) async {
final PermissionState ps = await permissionCheck(
requestOption: PermissionRequestOption(
androidPermission: AndroidPermission(
type: pickerConfig.requestType,
mediaLocation: false,
),
),
);
final PermissionState ps = await permissionCheck();
final AssetPathEntity pathEntity = AssetPathEntity(
id: 'test',
name: 'pathEntity',
Expand Down

0 comments on commit e0749c9

Please sign in to comment.