Skip to content

Commit d7986fb

Browse files
authored
PermissionState.hasAccess (#792)
1 parent 20fcde6 commit d7986fb

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ that can be found in the LICENSE file. -->
99
### Improvements
1010

1111
- Improve assets change notify with better methods signature and checks. (#790)
12+
- Add `PermissionState.hasAccess` getter for better condition judgement. (#792)
1213

1314
### Fixes
1415

example/lib/main.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ class _SimpleExamplePageState extends State<_SimpleExamplePage> {
5959
if (!mounted) {
6060
return;
6161
}
62-
// Further requests can be only procceed with authorized or limited.
63-
if (ps != PermissionState.authorized && ps != PermissionState.limited) {
62+
// Further requests can be only proceed with authorized or limited.
63+
if (!ps.hasAccess) {
6464
setState(() {
6565
_isLoading = false;
6666
});
67-
showToast('Permission is not granted.');
67+
showToast('Permission is not accessible.');
6868
return;
6969
}
7070
// Obtain assets using the path entity.

lib/src/internal/extensions.dart

+6
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@ extension PermissionStateExt on PermissionState {
99
bool get isAuth {
1010
return this == PermissionState.authorized;
1111
}
12+
13+
/// Whether the permission can access assets partially or fully,
14+
bool get hasAccess {
15+
return this == PermissionState.authorized ||
16+
this == PermissionState.limited;
17+
}
1218
}

test/internal/extensions_test.dart

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 The FlutterCandies author. All rights reserved.
2+
// Use of this source code is governed by an Apache license that can be found
3+
// in the LICENSE file.
4+
5+
import 'package:flutter_test/flutter_test.dart';
6+
import 'package:photo_manager/photo_manager.dart';
7+
8+
void main() {
9+
test('Permission extensions equality test', () async {
10+
const PermissionState permission = PermissionState.limited;
11+
expect(
12+
permission.isAuth == (permission == PermissionState.authorized),
13+
equals(true),
14+
);
15+
expect(
16+
permission.hasAccess ==
17+
(permission == PermissionState.authorized ||
18+
permission == PermissionState.limited),
19+
equals(true),
20+
);
21+
});
22+
}

test/photo_manager_test.dart

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2018 The FlutterCandies author. All rights reserved.
2+
// Use of this source code is governed by an Apache license that can be found
3+
// in the LICENSE file.
4+
15
// ignore_for_file: use_named_constants
26
import 'package:flutter_test/flutter_test.dart';
37
import 'package:photo_manager/photo_manager.dart';

0 commit comments

Comments
 (0)