Skip to content

Commit 04bfb65

Browse files
authored
🐛 Fixes permission requests (#597)
- Support limited permission displays on Android. This also deprecates `iOSPermissionOverlay`. - Requests with the correct options with the picker. - Improves the limited overlay padding on Android. - Adds permission request lock for the picker state.
1 parent 2d57008 commit 04bfb65

File tree

11 files changed

+74
-12
lines changed

11 files changed

+74
-12
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ that can be found in the LICENSE file. -->
77
> [!IMPORTANT]
88
> See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions.
99
10+
## 9.1.0
11+
12+
### Fixes
13+
14+
- Requests with the correct options with the picker.
15+
16+
### Improvements
17+
18+
- Support limited permission displays on Android.
19+
- Improves the limited overlay padding on Android.
20+
- Adds permission request lock for the picker state.
21+
1022
## 9.0.5
1123

1224
### Fixes

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
88
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
99
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
10+
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
1011

1112
<application
1213
android:label="Wechat Assets Picker Example"

example/lib/customs/pickers/directory_file_asset_picker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ class FileAssetPickerBuilder
11901190
fit: StackFit.expand,
11911191
children: <Widget>[
11921192
if (isAppleOS(context)) appleOSLayout(c) else androidLayout(c),
1193-
if (Platform.isIOS) iOSPermissionOverlay(c),
1193+
permissionOverlay(c),
11941194
],
11951195
),
11961196
),

example/lib/customs/pickers/multi_tabs_assets_picker.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by an Apache license that can be found
33
// in the LICENSE file.
44

5-
import 'dart:io';
65
import 'dart:math' as math;
76

87
import 'package:flutter/material.dart';
@@ -562,7 +561,7 @@ class MultiTabAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
562561
appleOSLayout(context)
563562
else
564563
androidLayout(context),
565-
if (Platform.isIOS) iOSPermissionOverlay(context),
564+
permissionOverlay(context),
566565
],
567566
),
568567
),

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: 9.0.5+54
3+
version: 9.1.0+55
44
publish_to: none
55

66
environment:

guides/migration_guide.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ that can be found in the LICENSE file. -->
66

77
This document gathered all breaking changes and migrations requirement between major versions.
88

9-
## Major versions
9+
## Breaking changes in versions
1010

11+
- [9.1.0](#910)
1112
- [9.0.0](#900)
1213
- [8.6.0](#860)
1314
- [8.3.0](#830)
@@ -17,6 +18,14 @@ This document gathered all breaking changes and migrations requirement between m
1718
- [6.0.0](#600)
1819
- [5.0.0](#500)
1920

21+
## 9.1.0
22+
23+
### Deprecates `iOSPermissionOverlay`
24+
25+
Due to the support of the limited permission status on Android,
26+
the permission overlay will also displays on Android.
27+
Thus, `iOSPermissionOverlay` is now migrating to `permissionOverlay`.
28+
2029
## 9.0.0
2130

2231
### View assets signature change

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by an Apache license that can be found
33
// in the LICENSE file.
44

5-
import 'dart:io' show Platform;
65
import 'dart:math' as math;
76
import 'dart:typed_data' as typed_data;
87
import 'dart:ui' as ui;
@@ -574,7 +573,13 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
574573
}
575574

576575
/// The overlay when the permission is limited on iOS.
576+
@Deprecated('Use permissionOverlay instead. This will be removed in 10.0.0')
577577
Widget iOSPermissionOverlay(BuildContext context) {
578+
return permissionOverlay(context);
579+
}
580+
581+
/// The overlay when the permission is limited.
582+
Widget permissionOverlay(BuildContext context) {
578583
final Size size = MediaQuery.sizeOf(context);
579584
final Widget closeButton = Container(
580585
margin: const EdgeInsetsDirectional.only(start: 16, top: 4),
@@ -652,7 +657,7 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
652657
child: Semantics(
653658
sortKey: const OrdinalSortKey(0),
654659
child: Container(
655-
padding: MediaQuery.paddingOf(context),
660+
padding: EdgeInsets.only(top: MediaQuery.paddingOf(context).top),
656661
color: context.theme.canvasColor,
657662
child: Column(
658663
children: <Widget>[
@@ -661,6 +666,12 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
661666
goToSettingsButton,
662667
SizedBox(height: size.height / 18),
663668
accessLimitedButton,
669+
SizedBox(
670+
height: math.max(
671+
MediaQuery.paddingOf(context).bottom,
672+
24.0,
673+
),
674+
),
664675
],
665676
),
666677
),
@@ -2220,7 +2231,7 @@ class DefaultAssetPickerBuilderDelegate
22202231
appleOSLayout(context)
22212232
else
22222233
androidLayout(context),
2223-
if (Platform.isIOS) iOSPermissionOverlay(context),
2234+
permissionOverlay(context),
22242235
],
22252236
),
22262237
),

lib/src/delegates/asset_picker_delegate.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class AssetPickerDelegate {
9696
);
9797
final Widget picker = AssetPicker<AssetEntity, AssetPathEntity>(
9898
key: key,
99+
permissionRequestOption: permissionRequestOption,
99100
builder: DefaultAssetPickerBuilderDelegate(
100101
provider: provider,
101102
initialPermission: ps,
@@ -157,6 +158,7 @@ class AssetPickerDelegate {
157158
await permissionCheck(requestOption: permissionRequestOption);
158159
final Widget picker = AssetPicker<Asset, Path>(
159160
key: key,
161+
permissionRequestOption: permissionRequestOption,
160162
builder: delegate,
161163
);
162164
final List<Asset>? result = await Navigator.maybeOf(

lib/src/widget/asset_picker.dart

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by an Apache license that can be found
33
// in the LICENSE file.
44

5+
import 'dart:async';
6+
57
import 'package:flutter/material.dart';
68
import 'package:flutter/services.dart';
79
import 'package:photo_manager/photo_manager.dart';
@@ -15,8 +17,13 @@ import 'asset_picker_page_route.dart';
1517
AssetPickerDelegate _pickerDelegate = const AssetPickerDelegate();
1618

1719
class AssetPicker<Asset, Path> extends StatefulWidget {
18-
const AssetPicker({super.key, required this.builder});
20+
const AssetPicker({
21+
super.key,
22+
required this.permissionRequestOption,
23+
required this.builder,
24+
});
1925

26+
final PermissionRequestOption permissionRequestOption;
2027
final AssetPickerBuilderDelegate<Asset, Path> builder;
2128

2229
/// Provide another [AssetPickerDelegate] which override with
@@ -99,6 +106,8 @@ class AssetPicker<Asset, Path> extends StatefulWidget {
99106

100107
class AssetPickerState<Asset, Path> extends State<AssetPicker<Asset, Path>>
101108
with TickerProviderStateMixin, WidgetsBindingObserver {
109+
Completer<PermissionState>? permissionStateLock;
110+
102111
@override
103112
void initState() {
104113
super.initState();
@@ -111,8 +120,10 @@ class AssetPickerState<Asset, Path> extends State<AssetPicker<Asset, Path>>
111120
void didChangeAppLifecycleState(AppLifecycleState state) {
112121
super.didChangeAppLifecycleState(state);
113122
if (state == AppLifecycleState.resumed) {
114-
PhotoManager.requestPermissionExtend().then((PermissionState ps) {
115-
widget.builder.permission.value = ps;
123+
requestPermission().then((ps) {
124+
if (mounted) {
125+
widget.builder.permission.value = ps;
126+
}
116127
});
117128
}
118129
}
@@ -134,6 +145,22 @@ class AssetPickerState<Asset, Path> extends State<AssetPicker<Asset, Path>>
134145
});
135146
}
136147

148+
Future<PermissionState> requestPermission() {
149+
if (permissionStateLock != null) {
150+
return permissionStateLock!.future;
151+
}
152+
final lock = Completer<PermissionState>();
153+
permissionStateLock = lock;
154+
Future(
155+
() => PhotoManager.requestPermissionExtend(
156+
requestOption: widget.permissionRequestOption,
157+
),
158+
).then(lock.complete).catchError(lock.completeError).whenComplete(() {
159+
permissionStateLock = null;
160+
});
161+
return lock.future;
162+
}
163+
137164
@override
138165
Widget build(BuildContext context) {
139166
return widget.builder.build(context);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: wechat_assets_picker
2-
version: 9.0.5
2+
version: 9.1.0
33
description: |
44
An image picker (also with videos and audio)
55
for Flutter projects based on WeChat's UI,

0 commit comments

Comments
 (0)