From fb574162115e702012a0e2e92ecc7dce8488503b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Andra=C5=A1ec?= Date: Mon, 10 Oct 2022 09:54:38 +0000 Subject: [PATCH] Fix: SentryDevice cast error (#1059) Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> --- CHANGELOG.md | 1 + dart/lib/src/protocol/sentry_device.dart | 4 ++-- dart/test/protocol/sentry_device_test.dart | 13 +++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3fc27ce76..3c77db31b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Handle traces sampler exception ([#1040](https://github.com/getsentry/sentry-dart/pull/1040)) - tracePropagationTargets ignores invalid Regex ([#1043](https://github.com/getsentry/sentry-dart/pull/1043)) +- SentryDevice cast error ([#1059](https://github.com/getsentry/sentry-dart/pull/1059)) ### Features diff --git a/dart/lib/src/protocol/sentry_device.dart b/dart/lib/src/protocol/sentry_device.dart index f9aa888a6f..8b030b1f19 100644 --- a/dart/lib/src/protocol/sentry_device.dart +++ b/dart/lib/src/protocol/sentry_device.dart @@ -226,8 +226,8 @@ class SentryDevice { manufacturer: data['manufacturer'], brand: data['brand'], screenResolution: data['screen_resolution'], - screenHeightPixels: data['screen_height_pixels'], - screenWidthPixels: data['screen_width_pixels'], + screenHeightPixels: data['screen_height_pixels']?.toInt(), + screenWidthPixels: data['screen_width_pixels']?.toInt(), screenDensity: data['screen_density'], screenDpi: data['screen_dpi'], online: data['online'], diff --git a/dart/test/protocol/sentry_device_test.dart b/dart/test/protocol/sentry_device_test.dart index 97c0eabac8..77d41655e0 100644 --- a/dart/test/protocol/sentry_device_test.dart +++ b/dart/test/protocol/sentry_device_test.dart @@ -102,6 +102,19 @@ void main() { true, ); }); + + test('fromJson double screen_height_pixels and screen_width_pixels', () { + sentryDeviceJson['screen_height_pixels'] = 100.0; + sentryDeviceJson['screen_width_pixels'] = 100.0; + + final sentryDevice = SentryDevice.fromJson(sentryDeviceJson); + final json = sentryDevice.toJson(); + + expect( + MapEquality().equals(sentryDeviceJson, json), + true, + ); + }); }); group('copyWith', () {