diff --git a/CHANGELOG.md b/CHANGELOG.md index e073b7b29f..fc9e7352bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## Unreleased + +### Features + +- Accept `Map` in `Hint` class ([#1807](https://github.com/getsentry/sentry-dart/pull/1807)) + - Please check if everything works as expected when using `Hint` + - Factory constructor `Hint.withMap(Map map)` now takes `Map` instead of `Map` + - Method `hint.addAll(Map keysAndValues)` now takes `Map` instead of `Map` + - Method `set(String key, dynamic value)` now takes value of `dynamic` instead of `Object` + - Method `hint.get(String key)` now returns `dynamic` instead of `Object?` + ## 7.15.0 ### Features diff --git a/dart/lib/src/hint.dart b/dart/lib/src/hint.dart index 87620d7ba1..aaa614518c 100644 --- a/dart/lib/src/hint.dart +++ b/dart/lib/src/hint.dart @@ -40,7 +40,7 @@ import 'sentry_attachment/sentry_attachment.dart'; /// }; /// ``` class Hint { - final Map _internalStorage = {}; + final Map _internalStorage = {}; final List attachments = []; @@ -62,7 +62,7 @@ class Hint { return hint; } - factory Hint.withMap(Map map) { + factory Hint.withMap(Map map) { final hint = Hint(); hint.addAll(map); return hint; @@ -80,17 +80,19 @@ class Hint { return hint; } - // Objects + // Key/Value Storage - void addAll(Map keysAndValues) { - _internalStorage.addAll(keysAndValues); + void addAll(Map keysAndValues) { + final withoutNullValues = + keysAndValues.map((key, value) => MapEntry(key, value ?? "null")); + _internalStorage.addAll(withoutNullValues); } - void set(String key, Object value) { - _internalStorage[key] = value; + void set(String key, dynamic value) { + _internalStorage[key] = value ?? "null"; } - Object? get(String key) { + dynamic get(String key) { return _internalStorage[key]; } diff --git a/dart/test/hint_test.dart b/dart/test/hint_test.dart index d46a022405..04c09a28a0 100644 --- a/dart/test/hint_test.dart +++ b/dart/test/hint_test.dart @@ -82,6 +82,23 @@ void main() { expect(sut.screenshot, attachment); expect(sut.viewHierarchy, attachment); }); + + test('Hint init with map null fallback', () { + final hint = Hint.withMap({'fixture-key': null}); + expect("null", hint.get("fixture-key")); + }); + + test('Hint addAll with map null fallback', () { + final hint = Hint(); + hint.addAll({'fixture-key': null}); + expect("null", hint.get("fixture-key")); + }); + + test('Hint set with null value fallback', () { + final hint = Hint(); + hint.set("fixture-key", null); + expect("null", hint.get("fixture-key")); + }); } class Fixture {