Skip to content

Commit

Permalink
Accept Map<String, dynamic> in Hint class (#1807)
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase authored Jan 23, 2024
1 parent 294b7f0 commit 270031a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
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

0 comments on commit 270031a

Please sign in to comment.