Skip to content

Commit

Permalink
[camerax] Fix _getResolutionSelectorFromPreset NPE (#5287)
Browse files Browse the repository at this point in the history
Fixes a mistake causing a NPE in `_getResolutionSelectorFromPreset`. Essentially, `boundSize` cannot be null except for one case (choosing the maximum available resolution), but the mistake I made was not allowing for that case to be valid.

(1/2 fixes really) Fixes flutter/flutter#135293.
  • Loading branch information
camsim99 authored Nov 2, 2023
1 parent e4c5159 commit 5b03a38
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 4 additions & 0 deletions packages/camera/camera_android_camerax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0+22

* Fixes `_getResolutionSelectorFromPreset` null pointer error.

## 0.5.0+21

* Changes fallback resolution strategies for camera use cases to look for a higher resolution if neither the desired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,28 +880,30 @@ class AndroidCameraCameraX extends CameraPlatform {
break;
case ResolutionPreset.max:
// Automatically set strategy to choose highest available.
resolutionStrategy = _shouldCreateDetachedObjectForTesting
? ResolutionStrategy.detachedHighestAvailableStrategy()
: ResolutionStrategy.highestAvailableStrategy();
break;
if (_shouldCreateDetachedObjectForTesting) {
resolutionStrategy =
ResolutionStrategy.detachedHighestAvailableStrategy();
return ResolutionSelector.detached(
resolutionStrategy: resolutionStrategy);
}
resolutionStrategy = ResolutionStrategy.highestAvailableStrategy();
return ResolutionSelector(resolutionStrategy: resolutionStrategy);
case null:
// If no preset is specified, default to CameraX's default behavior
// for each UseCase.
return null;
}

if (_shouldCreateDetachedObjectForTesting) {
resolutionStrategy ??= ResolutionStrategy.detached(
resolutionStrategy = ResolutionStrategy.detached(
boundSize: boundSize, fallbackRule: fallbackRule);
return ResolutionSelector.detached(
resolutionStrategy: resolutionStrategy);
}

resolutionStrategy ??=
ResolutionStrategy(boundSize: boundSize!, fallbackRule: fallbackRule);
return ResolutionSelector(
resolutionStrategy: ResolutionStrategy(
boundSize: boundSize!, fallbackRule: fallbackRule));
resolutionStrategy =
ResolutionStrategy(boundSize: boundSize, fallbackRule: fallbackRule);
return ResolutionSelector(resolutionStrategy: resolutionStrategy);
}

/// Returns the [QualitySelector] that maps to the specified resolution
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_android_camerax/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_android_camerax
description: Android implementation of the camera plugin using the CameraX library.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.5.0+21
version: 0.5.0+22

environment:
sdk: ">=2.19.0 <4.0.0"
Expand Down

0 comments on commit 5b03a38

Please sign in to comment.