···
final isLoading = context.select<FeedProvider, bool>((p) => p.isLoading);
final error = context.select<FeedProvider, String?>((p) => p.error);
final posts = context.select<FeedProvider, List<FeedViewPost>>(
···
padding: const EdgeInsets.all(24),
···
color: const Color(0xFFFF6B35),
controller: _scrollController,
-
itemCount: posts.length + (isLoadingMore ? 1 : 0),
itemBuilder: (context, index) {
if (index == posts.length) {
-
padding: EdgeInsets.all(16),
-
child: CircularProgressIndicator(color: Color(0xFFFF6B35)),
final post = posts[index];
···
final isLoading = context.select<FeedProvider, bool>((p) => p.isLoading);
final error = context.select<FeedProvider, String?>((p) => p.error);
+
// IMPORTANT: This works because FeedProvider replaces the list (_posts = ...)
+
// rather than mutating it in-place (_posts.addAll(...)).
+
// If you change FeedProvider to use in-place mutations, this will break
+
// because Lists use reference equality by default.
final posts = context.select<FeedProvider, List<FeedViewPost>>(
···
+
// Error state (only show full-screen error when no posts loaded yet)
+
// If we have posts but pagination failed, we'll show the error at the bottom
+
if (error != null && posts.isEmpty) {
padding: const EdgeInsets.all(24),
···
color: const Color(0xFFFF6B35),
controller: _scrollController,
+
// Add extra item for loading indicator or pagination error
+
itemCount: posts.length + (isLoadingMore || error != null ? 1 : 0),
itemBuilder: (context, index) {
+
// Footer: loading indicator or error message
if (index == posts.length) {
+
// Show loading indicator for pagination
+
padding: EdgeInsets.all(16),
+
child: CircularProgressIndicator(color: Color(0xFFFF6B35)),
+
// Show error message for pagination failures
+
margin: const EdgeInsets.all(16),
+
padding: const EdgeInsets.all(16),
+
decoration: BoxDecoration(
+
color: const Color(0xFF1A1F26),
+
borderRadius: BorderRadius.circular(8),
+
border: Border.all(color: const Color(0xFFFF6B35)),
+
color: Color(0xFFFF6B35),
+
const SizedBox(height: 8),
+
_getUserFriendlyError(error),
+
style: const TextStyle(
+
color: Color(0xFFB6C2D2),
+
textAlign: TextAlign.center,
+
const SizedBox(height: 12),
+
final feedProvider = Provider.of<FeedProvider>(
+
feedProvider.clearError();
+
feedProvider.loadMore();
+
style: TextButton.styleFrom(
+
foregroundColor: const Color(0xFFFF6B35),
+
child: const Text('Retry'),
final post = posts[index];