diff --git a/lib/core/note.dart b/lib/core/note.dart index 65b079f8..0e75b6d8 100644 --- a/lib/core/note.dart +++ b/lib/core/note.dart @@ -36,7 +36,7 @@ class Note with NotesNotifier { DateTime _modified; String _body = ""; NoteType _type = NoteType.Unknown; - List _tags = []; + Set _tags = {}; MdYamlDoc _data = MdYamlDoc(); NoteSerializer noteSerializer = NoteSerializer(); @@ -125,11 +125,11 @@ class Note with NotesNotifier { _notifyModified(); } - List get tags { + Set get tags { return _tags; } - set tags(List tags) { + set tags(Set tags) { if (!canHaveMetadata) return; _tags = tags; diff --git a/lib/core/note_serializer.dart b/lib/core/note_serializer.dart index 11237150..c2684277 100644 --- a/lib/core/note_serializer.dart +++ b/lib/core/note_serializer.dart @@ -60,7 +60,7 @@ class NoteSerializer implements NoteSerializerInterface { if (note.tags.isEmpty) { data.props.remove(settings.tagsKey); } else { - data.props[settings.tagsKey] = note.tags; + data.props[settings.tagsKey] = note.tags.toList(); } data.body = emojiParser.unemojify(note.body); @@ -108,7 +108,7 @@ class NoteSerializer implements NoteSerializerInterface { try { var tags = data.props[settings.tagsKey] as YamlList; if (tags != null) { - note.tags = tags.map((t) => t.toString()).toList(); + note.tags = tags.map((t) => t.toString()).toSet(); } } catch (e) { Log.e("Note Decoding Failed: $e"); diff --git a/test/note_test.dart b/test/note_test.dart index f53a7a52..434c6352 100644 --- a/test/note_test.dart +++ b/test/note_test.dart @@ -93,11 +93,11 @@ Hello"""; var note = Note(parentFolder, notePath); await note.load(); - expect(note.tags[0], 'A'); - expect(note.tags[1], 'B'); + expect(note.tags.contains('A'), true); + expect(note.tags.contains('B'), true); expect(note.tags.length, 2); - note.tags = [...note.tags]..add('C'); + note.tags = {...note.tags}..add('C'); note.tags.add('D'); note.tags.remove('B');