Skip to content

Commit 5b03a38

Browse files
authored
[camerax] Fix _getResolutionSelectorFromPreset NPE (flutter#5287)
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#135293.
1 parent e4c5159 commit 5b03a38

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

packages/camera/camera_android_camerax/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.0+22
2+
3+
* Fixes `_getResolutionSelectorFromPreset` null pointer error.
4+
15
## 0.5.0+21
26

37
* Changes fallback resolution strategies for camera use cases to look for a higher resolution if neither the desired

packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -880,28 +880,30 @@ class AndroidCameraCameraX extends CameraPlatform {
880880
break;
881881
case ResolutionPreset.max:
882882
// Automatically set strategy to choose highest available.
883-
resolutionStrategy = _shouldCreateDetachedObjectForTesting
884-
? ResolutionStrategy.detachedHighestAvailableStrategy()
885-
: ResolutionStrategy.highestAvailableStrategy();
886-
break;
883+
if (_shouldCreateDetachedObjectForTesting) {
884+
resolutionStrategy =
885+
ResolutionStrategy.detachedHighestAvailableStrategy();
886+
return ResolutionSelector.detached(
887+
resolutionStrategy: resolutionStrategy);
888+
}
889+
resolutionStrategy = ResolutionStrategy.highestAvailableStrategy();
890+
return ResolutionSelector(resolutionStrategy: resolutionStrategy);
887891
case null:
888892
// If no preset is specified, default to CameraX's default behavior
889893
// for each UseCase.
890894
return null;
891895
}
892896

893897
if (_shouldCreateDetachedObjectForTesting) {
894-
resolutionStrategy ??= ResolutionStrategy.detached(
898+
resolutionStrategy = ResolutionStrategy.detached(
895899
boundSize: boundSize, fallbackRule: fallbackRule);
896900
return ResolutionSelector.detached(
897901
resolutionStrategy: resolutionStrategy);
898902
}
899903

900-
resolutionStrategy ??=
901-
ResolutionStrategy(boundSize: boundSize!, fallbackRule: fallbackRule);
902-
return ResolutionSelector(
903-
resolutionStrategy: ResolutionStrategy(
904-
boundSize: boundSize!, fallbackRule: fallbackRule));
904+
resolutionStrategy =
905+
ResolutionStrategy(boundSize: boundSize, fallbackRule: fallbackRule);
906+
return ResolutionSelector(resolutionStrategy: resolutionStrategy);
905907
}
906908

907909
/// Returns the [QualitySelector] that maps to the specified resolution

packages/camera/camera_android_camerax/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera_android_camerax
22
description: Android implementation of the camera plugin using the CameraX library.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.5.0+21
5+
version: 0.5.0+22
66

77
environment:
88
sdk: ">=2.19.0 <4.0.0"

0 commit comments

Comments
 (0)