Skip to content

Commit

Permalink
🐛 Use PermissionRequestOption as much as possible (fluttercandies#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Feb 6, 2024
1 parent eaab93c commit 346fecb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ that can be found in the LICENSE file. -->
### Fixes

- Fix previewing selected assets behavior.
- Use `PermissionRequestOption` as much as possible.

## 9.0.0-dev.2

Expand Down
14 changes: 8 additions & 6 deletions lib/src/delegates/asset_picker_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,19 @@ class AssetPickerDelegate {
BuildContext context, {
Key? key,
AssetPickerConfig pickerConfig = const AssetPickerConfig(),
PermissionRequestOption? permissionRequestOption,
bool useRootNavigator = true,
AssetPickerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
}) async {
final PermissionState ps = await permissionCheck(
requestOption: PermissionRequestOption(
androidPermission: AndroidPermission(
type: pickerConfig.requestType,
mediaLocation: false,
),
permissionRequestOption ??= PermissionRequestOption(
androidPermission: AndroidPermission(
type: pickerConfig.requestType,
mediaLocation: false,
),
);
final PermissionState ps = await permissionCheck(
requestOption: permissionRequestOption,
);
final AssetPickerPageRoute<List<AssetEntity>> route =
pageRouteBuilder?.call(const SizedBox.shrink()) ??
AssetPickerPageRoute<List<AssetEntity>>(
Expand Down
9 changes: 7 additions & 2 deletions lib/src/widget/asset_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class AssetPicker<Asset, Path> extends StatefulWidget {
static Future<List<AssetEntity>?> pickAssets(
BuildContext context, {
Key? key,
PermissionRequestOption? permissionRequestOption,
AssetPickerConfig pickerConfig = const AssetPickerConfig(),
bool useRootNavigator = true,
AssetPickerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
Expand All @@ -49,6 +50,7 @@ class AssetPicker<Asset, Path> extends StatefulWidget {
context,
key: key,
pickerConfig: pickerConfig,
permissionRequestOption: permissionRequestOption,
useRootNavigator: useRootNavigator,
pageRouteBuilder: pageRouteBuilder,
);
Expand All @@ -58,15 +60,18 @@ class AssetPicker<Asset, Path> extends StatefulWidget {
static Future<List<Asset>?> pickAssetsWithDelegate<Asset, Path,
PickerProvider extends AssetPickerProvider<Asset, Path>>(
BuildContext context, {
Key? key,
required AssetPickerBuilderDelegate<Asset, Path> delegate,
bool useRootNavigator = true,
PermissionRequestOption permissionRequestOption =
const PermissionRequestOption(),
Key? key,
AssetPickerPageRouteBuilder<List<Asset>>? pageRouteBuilder,
bool useRootNavigator = true,
}) {
return _pickerDelegate.pickAssetsWithDelegate<Asset, Path, PickerProvider>(
context,
key: key,
delegate: delegate,
permissionRequestOption: permissionRequestOption,
useRootNavigator: useRootNavigator,
pageRouteBuilder: pageRouteBuilder,
);
Expand Down
14 changes: 8 additions & 6 deletions test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,19 @@ class TestAssetPickerDelegate extends AssetPickerDelegate {
BuildContext context, {
Key? key,
AssetPickerConfig pickerConfig = const AssetPickerConfig(),
PermissionRequestOption? permissionRequestOption,
bool useRootNavigator = true,
AssetPickerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
}) async {
final PermissionState ps = await permissionCheck(
requestOption: PermissionRequestOption(
androidPermission: AndroidPermission(
type: pickerConfig.requestType,
mediaLocation: false,
),
permissionRequestOption ??= PermissionRequestOption(
androidPermission: AndroidPermission(
type: pickerConfig.requestType,
mediaLocation: false,
),
);
final PermissionState ps = await permissionCheck(
requestOption: permissionRequestOption,
);
final AssetPathEntity pathEntity = AssetPathEntity(
id: 'test',
name: 'pathEntity',
Expand Down

0 comments on commit 346fecb

Please sign in to comment.