Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.12.0+1

* Makes `Optional.of` constructor `const`.

## 0.12.0

* Adds support for video stabilization.
Expand Down Expand Up @@ -838,4 +842,4 @@ Method changes:

## 0.0.1

* Initial release
* Initial release
8 changes: 1 addition & 7 deletions packages/camera/camera/lib/src/camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1049,13 +1049,7 @@ class Optional<T> extends IterableBase<T> {
const Optional.absent() : _value = null;

/// Constructs an Optional of the given [value].
///
/// Throws [ArgumentError] if [value] is null.
Optional.of(T value) : _value = value {
// TODO(cbracken): Delete and make this ctor const once mixed-mode
// execution is no longer around.
ArgumentError.checkNotNull(value);
}
const Optional.of(T value) : _value = value;
Comment on lines 1051 to +1052

Choose a reason for hiding this comment

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

medium

As you've noted in the PR description, this Optional<T> class is duplicated across multiple packages. This change is a good example of why that's a maintainability issue, as it has to be applied in four separate places. It would be a great improvement to refactor this in a follow-up PR.

Two potential approaches you mentioned are:

  1. Move Optional<T> to a shared package (e.g., camera_platform_interface).
  2. Replace its usage with a private sentinel pattern, similar to what's done in the Flutter framework for ThemeData.copyWith.

Moving it to a shared package seems like a good path forward. This would also be a good opportunity to audit the implementation for consistency, as there are some subtle differences between the duplicated versions (e.g., in the transform method signature).


/// Constructs an Optional of the given [value].
///
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing
Dart.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.12.0
version: 0.12.0+1

environment:
sdk: ^3.9.0
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera/test/camera_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3664,7 +3664,7 @@ void main() {
cameraController.value = cameraController.value.copyWith(
isPreviewPaused: false,
deviceOrientation: DeviceOrientation.portraitUp,
lockedCaptureOrientation: Optional<DeviceOrientation>.of(
lockedCaptureOrientation: const Optional<DeviceOrientation>.of(
DeviceOrientation.landscapeRight,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,7 @@ class Optional<T> extends IterableBase<T> {
const Optional.absent() : _value = null;

/// Constructs an Optional of the given [value].
///
/// Throws [ArgumentError] if [value] is null.
Optional.of(T value) : _value = value {
// TODO(cbracken): Delete and make this ctor const once mixed-mode
// execution is no longer around.
ArgumentError.checkNotNull(value);
}
const Optional.of(T value) : _value = value;

/// Constructs an Optional of the given [value].
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,13 +898,7 @@ class Optional<T> extends IterableBase<T> {
const Optional.absent() : _value = null;

/// Constructs an Optional of the given [value].
///
/// Throws [ArgumentError] if [value] is null.
Optional.of(T value) : _value = value {
// TODO(cbracken): Delete and make this ctor const once mixed-mode
// execution is no longer around.
ArgumentError.checkNotNull(value);
}
const Optional.of(T value) : _value = value;

/// Constructs an Optional of the given [value].
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,7 @@ class Optional<T> extends IterableBase<T> {
const Optional.absent() : _value = null;

/// Constructs an Optional of the given [value].
///
/// Throws [ArgumentError] if [value] is null.
Optional.of(T value) : _value = value {
// TODO(cbracken): Delete and make this ctor const once mixed-mode
// execution is no longer around.
ArgumentError.checkNotNull(value);
}
const Optional.of(T value) : _value = value;

/// Constructs an Optional of the given [value].
///
Expand Down
Loading