-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Camera] Made CameraController.isDisposed publicly accessible. Added unit Tests for the new implementation. #3193
Conversation
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
209cbde to
27f5cba
Compare
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
1 similar comment
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
|
@googlebot I consent. |
packages/camera/lib/camera.dart
Outdated
| /// True after [CameraController.dispose] has completed successfully. | ||
| bool get isDisposed => _isDisposed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we typically expose things like this guarded by asserts, so they're only valid in debug mode.
This is to discourage people from adding checks like this to release mode code, where it should never really be necessary.
IOW, making it easier to assert program correctness is great. Allowing someone to bog down code with 1000s of small checks that really should only be done during development is not as preferable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for providing feedback. I agree with the idea on only allowing this during during development. However I am not really sure how to "expose things like this guarded by asserts"?
Does this imply we don't expose a property but rather add assert statements to the methods? I feel a bit stupid here :P, but I just cannot wrap my head around it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// True after [CameraController.dispose] has completed successfully. | |
| bool get isDisposed => _isDisposed; | |
| /// Checks whether [CameraController.dispose] has completed successfully. | |
| /// | |
| /// This is a no-op when asserts are disabled. | |
| void debugDisposed() => assert(_isDisposed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe debugCheckDisposed or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bparrishMines what do you think?
In general it would be bad to have any code that can potentially access the CameraController when it is already disposed. This means having the debugCheckIsDisposed around should be helpful for developers trying to debug their application, but should not be used in production. This will also prevent code constructs like this, which has high risk on state conflicts:
var cameraController = CameraController();
// do stuff with the camera controller
...
if (cameraController.isDisposed) {
cameraController = CameraController();
}
// continue doing stuff with the camera controllerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, that makes sense to avoid that type of pattern. I'm fine with going with a debugCheckIsDisposed instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dnfield thank you for clarifying the coding structure that was very helpful. I took your recommendations and updates the pull request.
Note that I had to change:
void debugCheckIsDisposed() => assert(_isDisposed);to:
void debugCheckIsDisposed() {
assert(_isDisposed);
}otherwise we would receive a compile error.
I would appreciate it if you could have another look.
dnfield
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be guarded by asserts to discourage use in release mode.
37c0d92 to
bb7d4f4
Compare
dnfield
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if LG to @bparrishMines
bparrishMines
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good! Just one small comment on the test.
|
|
||
| controller.dispose(); | ||
|
|
||
| try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe returnsNormally is the standard way to make sure no Exception is thrown.
expect(() => controller.debugCheckIsDisposed(), returnsNormally);
bparrishMines
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I can merge for you once tests pass again.
|
Noticed that |
…unit Tests for the new implementation. (flutter#3193) * Update feedback from Flutter team * Removed obsolete dependency on mockito * Apply feedback on pull request * Bump version number * Update CHANGELOG description to reflect changes * Fix formatting * Refactor try..catch to returnsNormally * Fix formatting issues Co-authored-by: Maurits van Beusekom <[email protected]>
…unit Tests for the new implementation. (flutter#3193) * Update feedback from Flutter team * Removed obsolete dependency on mockito * Apply feedback on pull request * Bump version number * Update CHANGELOG description to reflect changes * Fix formatting * Refactor try..catch to returnsNormally * Fix formatting issues Co-authored-by: Maurits van Beusekom <[email protected]>
Description
Currently when you call
CameraController.Dispose()there is no way of knowing whether you disposed that CameraController.With this PR, the user can check if that CameraController has been disposed, by getting
CameraController.isDisposed.Since the current
test/camera_test.dartfile contains test for theCameraControllerclass located in thelib/new/src/camera_controller.dartI have moved it into thetest/new/camera_test.dartsub folder.I have added a new
test/camera_test.dartfile which contains the unit tests covering the newisDisposedproperty which was added to theCameraControllerclass located in the currentlib/camera.dartimplementation.Additionally I have added unit tests to the
test/new/camera_test.dartfile to ensure theisDisposedproperty (already) implemented in theCameraControllerclass located in thelib/new/src/camera_controller.dartfile is working properly.Related Issues
Fixes flutter/flutter#51630
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?