Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept Map<String, dynamic> in Hint class #1807

Merged
merged 18 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
- APM for isar ([#1726](https://github.com/getsentry/sentry-dart/pull/1726))
- Add isar breadcrumbs ([#1800](https://github.com/getsentry/sentry-dart/pull/1800))
- Starting with Flutter 3.16, Sentry adds the [`appFlavor`](https://api.flutter.dev/flutter/services/appFlavor-constant.html) to the `flutter_context` ([#1799](https://github.com/getsentry/sentry-dart/pull/1799))
- Accept `Map<String, dynamic>` in `Hint` class ([#1807](https://github.com/getsentry/sentry-dart/pull/1807))
denrase marked this conversation as resolved.
Show resolved Hide resolved
- 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?`
- Add beforeScreenshotCallback to SentryFlutterOptions ([#1805](https://github.com/getsentry/sentry-dart/pull/1805))
- Add support for `readTransaction` in `sqflite` ([#1819](https://github.com/getsentry/sentry-dart/pull/1819))

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
2 changes: 1 addition & 1 deletion flutter/example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
platform :ios, '11.0'
platform :ios, '12.0'
denrase marked this conversation as resolved.
Show resolved Hide resolved

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
2 changes: 1 addition & 1 deletion flutter/ios/sentry_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Sentry SDK for Flutter with support to native through sentry-cocoa.
s.dependency 'Sentry/HybridSDK', '8.18.0'
s.ios.dependency 'Flutter'
s.osx.dependency 'FlutterMacOS'
s.ios.deployment_target = '11.0'
s.ios.deployment_target = '12.0'
denrase marked this conversation as resolved.
Show resolved Hide resolved
# Flutter 3.7 requires 10.14
s.osx.deployment_target = '10.13'

Expand Down
Loading