toggleLike method
Flips the local like state for index, persists it into the item
cache (so revisiting within the window keeps the toggle), and fires
MovaFeedItem.onLikeChanged. A no-op returning (liked: false, count: 0)
if the item hasn't resolved yet.
翻转 index 的本地点赞状态,落回条目缓存(使窗口内滑走再滑回时切换结果仍在;窗口外由宿主回调持久化),
并触发 MovaFeedItem.onLikeChanged。若条目尚未解析则为空操作,返回
(liked: false, count: 0)。
index: the feed index to toggle / 要切换的 feed 索引
Implementation
({bool liked, int count}) toggleLike(int index) {
final item = _cache[index];
if (item == null) return (liked: false, count: 0);
final liked = !item.initialLiked;
final count = item.initialLikeCount + (liked ? 1 : -1);
_cache[index] = item.copyWith(initialLiked: liked, initialLikeCount: count);
item.onLikeChanged?.call(liked, count);
return (liked: liked, count: count);
}