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
4 changes: 3 additions & 1 deletion packages/camera/camera_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## NEXT
## 2.15.1

* Fixes `VideoRecordedEvent` equality and `hashCode` to compare the recorded file's path,
so equal events always have equal hash codes.
* Updates minimum supported SDK version to Flutter 3.44/Dart 3.12.

## 2.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ class VideoRecordedEvent extends CameraEvent {
super == other &&
other is VideoRecordedEvent &&
runtimeType == other.runtimeType &&
file.path == other.file.path &&
maxVideoDuration == other.maxVideoDuration;

@override
int get hashCode => Object.hash(super.hashCode, file, maxVideoDuration);
int get hashCode => Object.hash(super.hashCode, file.path, maxVideoDuration);
}
2 changes: 1 addition & 1 deletion packages/camera/camera_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.15.0
version: 2.15.1

environment:
sdk: ^3.12.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,66 @@ void main() {
expect(event.hashCode, expectedHashCode);
});
});

group('VideoRecordedEvent tests', () {
Comment thread
ChandraChaan marked this conversation as resolved.
Resolved
Comment thread
ChandraChaan marked this conversation as resolved.
Resolved
test('Equal when camera, file path and duration match', () {
final first = VideoRecordedEvent(1, XFile('/tmp/video.mp4'), const Duration(seconds: 5));
final second = VideoRecordedEvent(1, XFile('/tmp/video.mp4'), const Duration(seconds: 5));

expect(first, second);
expect(first.hashCode, second.hashCode);
});

test('Not equal when the file path differs', () {
final first = VideoRecordedEvent(1, XFile('/tmp/first.mp4'), null);
final second = VideoRecordedEvent(1, XFile('/tmp/second.mp4'), null);

expect(first, isNot(second));
});

test('Not equal when the camera ID differs', () {
final first = VideoRecordedEvent(1, XFile('/tmp/video.mp4'), const Duration(seconds: 5));
final second = VideoRecordedEvent(2, XFile('/tmp/video.mp4'), const Duration(seconds: 5));

expect(first, isNot(second));
});

test('Not equal when the max video duration differs', () {
final first = VideoRecordedEvent(1, XFile('/tmp/video.mp4'), const Duration(seconds: 5));
final second = VideoRecordedEvent(1, XFile('/tmp/video.mp4'), const Duration(seconds: 10));

expect(first, isNot(second));
});

test('Not equal when only one max video duration is null', () {
final withDuration = VideoRecordedEvent(
1,
XFile('/tmp/video.mp4'),
const Duration(seconds: 5),
);
final withoutDuration = VideoRecordedEvent(1, XFile('/tmp/video.mp4'), null);

expect(withDuration, isNot(withoutDuration));
expect(withoutDuration, isNot(withDuration));
});

test('hashCode should match hashCode of all properties', () {
final event = VideoRecordedEvent(1, XFile('/tmp/video.mp4'), const Duration(seconds: 5));
final int expectedHashCode = Object.hash(
event.cameraId.hashCode,
event.file.path,
event.maxVideoDuration,
);

expect(event.hashCode, expectedHashCode);
});

test('Round-trips through JSON as an equal event', () {
final event = VideoRecordedEvent(1, XFile('/tmp/video.mp4'), const Duration(seconds: 5));
final decoded = VideoRecordedEvent.fromJson(event.toJson());

expect(decoded, event);
expect(decoded.hashCode, event.hashCode);
});
});
}
Loading