Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 0.9.5

* Adds camera access permission handling logic on iOS to fix a related crash when first time using the camera.
* Adds camera access permission handling logic on iOS to fix a related crash when using the camera for the first time.

## 0.9.4+24

Expand All @@ -26,7 +26,7 @@

## 0.9.4+19

* Migrates deprecated Scaffold SnackBar methods to ScaffoldMessenger.
* Migrate deprecated Scaffold SnackBar methods to ScaffoldMessenger.

## 0.9.4+18

Expand Down
34 changes: 14 additions & 20 deletions packages/camera/camera/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,13 @@ Permission errors may be thrown when initializing the camera controller, and you

Here is a list of all permission error codes that can be thrown:

- CameraAccessDenied
Thrown when user denied the camera access permission.
- `CameraAccessDenied`: Thrown when user denies the camera access permission.

- CameraAccessDeniedWithoutPrompt
iOS only for now.
Thrown when user has previously denied the permission.
iOS does not allow prompting alert dialog a second time. Users will have to go to Settings > Privacy in order to enable camera access.
- `CameraAccessDeniedWithoutPrompt`: iOS only for now. Thrown when user has previously denied the permission. iOS does not allow prompting alert dialog a second time. Users will have to go to Settings > Privacy in order to enable camera access.

- CameraAccessRestricted
iOS only for now.
Thrown when camera access is restricted and users cannot grant permission (parental control).
- `CameraAccessRestricted`: iOS only for now. Thrown when camera access is restricted and users cannot grant permission (parental control).

- cameraPermission
Android and Web only.
A legacy error code for all kinds of camera permission errors.
- `cameraPermission`: Android and Web only. A legacy error code for all kinds of camera permission errors.

### Example

Expand Down Expand Up @@ -141,14 +133,16 @@ class _CameraAppState extends State<CameraApp> {
return;
}
setState(() {});
}).catchError((e) {
switch (e.code) {
case 'CameraAccessDenied':
print('User denied camera access.');
break;
default:
print('Handle other errors.');
break;
}).catchError((dynamic e) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use dynamic in modern Dart except where absolutely necessary; it bypasses all type checks. Object (or when needed, Object?) is almost always the better choice.

if (e is CameraException) {
switch (e.code) {
case 'CameraAccessDenied':
print('User denied camera access.');
break;
default:
print('Handle other errors.');
break;
}
}
});
}
Expand Down
3 changes: 1 addition & 2 deletions packages/camera/camera/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
break;
case 'cameraPermission':
// Android & web only
showInSnackBar(
'Legacy error code for all kinds of permission errors');
showInSnackBar('Unknown permission error.');
break;
default:
_showCameraException(e);
Expand Down
18 changes: 10 additions & 8 deletions packages/camera/camera/example/lib/readme_full_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ class _CameraAppState extends State<CameraApp> {
return;
}
setState(() {});
}).catchError((e) {
switch (e.code) {
case 'CameraAccessDenied':
print('User denied camera access.');
break;
default:
print('Handle other errors.');
break;
}).catchError((dynamic e) {
if (e is CameraException) {
switch (e.code) {
case 'CameraAccessDenied':
print('User denied camera access.');
break;
default:
print('Handle other errors.');
break;
}
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions packages/camera/camera/ios/Classes/CameraPermissionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
typedef void (^FLTCameraPermissionRequestCompletionHandler)(FlutterError *);

/// Requests camera access permission.
Comment thread
hellohuanlin marked this conversation as resolved.
///
/// If it is the first time requesting camera access, a permission dialog will show up on the
/// screen. Otherwise AVFoundation simply returns the user's previous choice, and in this case the
/// user will have to update the choice in Settings app.
///
/// @param handler if access permission is (or was previously) granted, completion handler will be
Comment thread
hellohuanlin marked this conversation as resolved.
/// called without error; Otherwise completion handler will be called with error. Handler can be
/// called on an arbitrary dispatch queue.
Expand Down