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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Next

- perf: Optimize Screenshot diff check ([#271](https://github.com/PostHog/posthog-flutter/pull/271))
- chore: improve survey color handling ([#233](https://github.com/PostHog/posthog-flutter/pull/233))

- feat: add `beforeSend` callback to `PostHogConfig` for dropping or modifying events before they are sent to PostHog ([#255](https://github.com/PostHog/posthog-flutter/pull/255))
Expand Down
19 changes: 9 additions & 10 deletions lib/src/replay/screenshot/screenshot_capturer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class ScreenshotCapturer {
return min(width / srcWidth, height / srcHeight);
}

Future<Uint8List?> _getImageBytes(ui.Image img) async {
Future<Uint8List?> _getImageBytes(ui.Image img,
{ui.ImageByteFormat format = ui.ImageByteFormat.png}) async {
try {
final ByteData? byteData =
await img.toByteData(format: ui.ImageByteFormat.png);
final ByteData? byteData = await img.toByteData(format: format);
if (byteData == null || byteData.lengthInBytes == 0) {
printIfDebug('Error: Failed to convert image to byte data.');
return null;
Expand Down Expand Up @@ -133,11 +133,10 @@ class ScreenshotCapturer {
final recorder = ui.PictureRecorder();
final canvas = Canvas(recorder);

// using png because its compressed, the native SDKs will decompress it
// and transform to webp or jpeg if needed
// https://github.com/brendan-duncan/image does not have webp encoding
Uint8List? pngBytes = await _getImageBytes(image);
if (pngBytes == null || pngBytes.isEmpty) {
// using rawRgba for the diff check because it is faster than png encoding
Uint8List? imageBytes =
await _getImageBytes(image, format: ui.ImageByteFormat.rawRgba);
if (imageBytes == null || imageBytes.isEmpty) {
printIfDebug(
'Error: Failed to convert image byte data to Uint8List.');
recorder.endRecording().dispose();
Expand All @@ -146,7 +145,7 @@ class ScreenshotCapturer {
return;
}

if (const PHListEquality().equals(pngBytes, statusView.imageBytes)) {
if (const PHListEquality().equals(imageBytes, statusView.imageBytes)) {
printIfDebug(
'Debug: Snapshot is the same as the last one, nothing changed, do nothing.');
recorder.endRecording().dispose();
Expand All @@ -155,7 +154,7 @@ class ScreenshotCapturer {
return;
}

statusView.imageBytes = pngBytes;
statusView.imageBytes = imageBytes;

try {
canvas.drawImage(image, Offset.zero, Paint());
Expand Down
Loading