Skip to content

Commit 270031a

Browse files
authored
Accept Map<String, dynamic> in Hint class (#1807)
1 parent 294b7f0 commit 270031a

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Accept `Map<String, dynamic>` in `Hint` class ([#1807](https://github.com/getsentry/sentry-dart/pull/1807))
8+
- Please check if everything works as expected when using `Hint`
9+
- Factory constructor `Hint.withMap(Map<String, dynamic> map)` now takes `Map<String, dynamic>` instead of `Map<String, Object>`
10+
- Method `hint.addAll(Map<String, dynamic> keysAndValues)` now takes `Map<String, dynamic>` instead of `Map<String, Object>`
11+
- Method `set(String key, dynamic value)` now takes value of `dynamic` instead of `Object`
12+
- Method `hint.get(String key)` now returns `dynamic` instead of `Object?`
13+
314
## 7.15.0
415

516
### Features

dart/lib/src/hint.dart

+10-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import 'sentry_attachment/sentry_attachment.dart';
4040
/// };
4141
/// ```
4242
class Hint {
43-
final Map<String, Object> _internalStorage = {};
43+
final Map<String, dynamic> _internalStorage = {};
4444

4545
final List<SentryAttachment> attachments = [];
4646

@@ -62,7 +62,7 @@ class Hint {
6262
return hint;
6363
}
6464

65-
factory Hint.withMap(Map<String, Object> map) {
65+
factory Hint.withMap(Map<String, dynamic> map) {
6666
final hint = Hint();
6767
hint.addAll(map);
6868
return hint;
@@ -80,17 +80,19 @@ class Hint {
8080
return hint;
8181
}
8282

83-
// Objects
83+
// Key/Value Storage
8484

85-
void addAll(Map<String, Object> keysAndValues) {
86-
_internalStorage.addAll(keysAndValues);
85+
void addAll(Map<String, dynamic> keysAndValues) {
86+
final withoutNullValues =
87+
keysAndValues.map((key, value) => MapEntry(key, value ?? "null"));
88+
_internalStorage.addAll(withoutNullValues);
8789
}
8890

89-
void set(String key, Object value) {
90-
_internalStorage[key] = value;
91+
void set(String key, dynamic value) {
92+
_internalStorage[key] = value ?? "null";
9193
}
9294

93-
Object? get(String key) {
95+
dynamic get(String key) {
9496
return _internalStorage[key];
9597
}
9698

dart/test/hint_test.dart

+17
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ void main() {
8282
expect(sut.screenshot, attachment);
8383
expect(sut.viewHierarchy, attachment);
8484
});
85+
86+
test('Hint init with map null fallback', () {
87+
final hint = Hint.withMap({'fixture-key': null});
88+
expect("null", hint.get("fixture-key"));
89+
});
90+
91+
test('Hint addAll with map null fallback', () {
92+
final hint = Hint();
93+
hint.addAll({'fixture-key': null});
94+
expect("null", hint.get("fixture-key"));
95+
});
96+
97+
test('Hint set with null value fallback', () {
98+
final hint = Hint();
99+
hint.set("fixture-key", null);
100+
expect("null", hint.get("fixture-key"));
101+
});
85102
}
86103

87104
class Fixture {

0 commit comments

Comments
 (0)