addToDictionaryHistory method
- {required DictionarySearchResult result}
Adds a DictionarySearchResult to dictionary history.
Implementation
void addToDictionaryHistory({required DictionarySearchResult result}) async {
MediaType mediaType = mediaTypes.values.toList()[currentHomeTabIndex];
if (mediaType != DictionaryMediaType.instance) {
shouldRefreshTabs = true;
ScrollController scrollController =
DictionaryMediaType.instance.scrollController;
if (scrollController.hasClients) {
scrollController.jumpTo(0);
}
}
if (result.headings.isEmpty || result.searchTerm.isEmpty) {
return;
}
_dictionaryHistory.deleteAll(_dictionaryHistory
.toMap()
.entries
.where((e) => e.value == result.id)
.map((e) => e.key)
.toList());
await _dictionaryHistory.add(result.id!);
int countInSameHistory = _dictionaryHistory.length;
if (maximumDictionaryHistoryItems < countInSameHistory) {
int surplus = countInSameHistory - maximumDictionaryHistoryItems;
_dictionaryHistory
.deleteAll(_dictionaryHistory.keys.toList().sublist(0, surplus));
}
}