fix: eliminate pull-to-refresh flicker by holding stale data during re-fetch

This commit is contained in:
2026-04-08 14:39:50 -04:00
parent 6c29b685e8
commit 3e888b6458
12 changed files with 70 additions and 14 deletions
+19
View File
@@ -71,6 +71,25 @@ class NewsNotifier extends AsyncNotifier<NewsState> {
);
}
/// Re-fetch the first page without clearing state (no flicker).
Future<void> refresh() async {
final current = state.value;
final items = await ref.read(newsApiProvider).getNewsItems(
days: 90,
limit: _limit,
offset: 0,
feedId: current?.selectedFeedId,
);
state = AsyncData(NewsState(
items: items,
offset: items.length,
hasMore: items.length == _limit,
loadingMore: false,
selectedFeedId: current?.selectedFeedId,
reactions: {for (final item in items) item.id: item.reaction},
));
}
Future<void> loadMore() async {
final current = state.value;
if (current == null || current.loadingMore || !current.hasMore) return;