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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## Unreleased

### Features

- Accept `Map<String, dynamic>` 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<String, dynamic> map)` now takes `Map<String, dynamic>` instead of `Map<String, Object>`
- Method `hint.addAll(Map<String, dynamic> keysAndValues)` now takes `Map<String, dynamic>` instead of `Map<String, Object>`
- 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
Expand Down
18 changes: 10 additions & 8 deletions dart/lib/src/hint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import 'sentry_attachment/sentry_attachment.dart';
/// };
/// ```
class Hint {
final Map<String, Object> _internalStorage = {};
final Map<String, dynamic> _internalStorage = {};

final List<SentryAttachment> attachments = [];

Expand All @@ -62,7 +62,7 @@ class Hint {
return hint;
}

factory Hint.withMap(Map<String, Object> map) {
factory Hint.withMap(Map<String, dynamic> map) {
final hint = Hint();
hint.addAll(map);
return hint;
Expand All @@ -80,17 +80,19 @@ class Hint {
return hint;
}

// Objects
// Key/Value Storage

void addAll(Map<String, Object> keysAndValues) {
_internalStorage.addAll(keysAndValues);
void addAll(Map<String, dynamic> 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];
}

Expand Down
17 changes: 17 additions & 0 deletions dart/test/hint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down