Browse Source

use url as entry label if title is not defined.

pull/3/head
Herbert Poul 4 years ago
parent
commit
4fc798e621
  1. 11
      lib/src/internal/extension_utils.dart
  2. 3
      lib/src/kdbx_entry.dart

11
lib/src/internal/extension_utils.dart

@ -34,6 +34,17 @@ extension ObjectExt<T> on T {
R let<R>(R Function(T that) op) => op(this); R let<R>(R Function(T that) op) => op(this);
} }
extension StringExt on String {
String takeUnlessBlank() => nullIfBlank();
String nullIfBlank() {
if (this == null || isEmpty) {
return null;
}
return this;
}
}
extension IterableExt<T> on Iterable<T> { extension IterableExt<T> on Iterable<T> {
T get singleOrNull => singleWhere((element) => true, orElse: () => null); T get singleOrNull => singleWhere((element) => true, orElse: () => null);
} }

3
lib/src/kdbx_entry.dart

@ -325,7 +325,8 @@ class KdbxEntry extends KdbxObject {
} }
String get label => String get label =>
_plainValue(KdbxKeyCommon.TITLE) ?? _plainValue(KdbxKeyCommon.URL); _plainValue(KdbxKeyCommon.TITLE)?.takeUnlessBlank() ??
_plainValue(KdbxKeyCommon.URL)?.takeUnlessBlank();
set label(String label) => setString(KdbxKeyCommon.TITLE, PlainValue(label)); set label(String label) => setString(KdbxKeyCommon.TITLE, PlainValue(label));

Loading…
Cancel
Save