Skip to content

Commit b6513f0

Browse files
committed
add fallback for null values
1 parent 17cfecd commit b6513f0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

dart/lib/src/hint.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,14 @@ class Hint {
8383
// Key/Value Storage
8484

8585
void addAll(Map<String, dynamic> keysAndValues) {
86-
_internalStorage.addAll(keysAndValues);
86+
final withoutNullValues = keysAndValues.map(
87+
(key, value) => MapEntry(key, value ?? "null")
88+
);
89+
_internalStorage.addAll(withoutNullValues);
8790
}
8891

8992
void set(String key, dynamic value) {
90-
_internalStorage[key] = value;
93+
_internalStorage[key] = value ?? "null";
9194
}
9295

9396
dynamic get(String key) {

dart/test/hint_test.dart

Lines changed: 17 additions & 0 deletions
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)