···
Widget build(BuildContext context) {
-
// Use select to only rebuild when specific fields change
final isAuthenticated = context.select<AuthProvider, bool>(
(p) => p.isAuthenticated,
-
final feedProvider = Provider.of<FeedProvider>(context);
backgroundColor: const Color(0xFF0B0F14),
···
title: Text(isAuthenticated ? 'Feed' : 'Explore'),
automaticallyImplyLeading: false,
-
body: SafeArea(child: _buildBody(feedProvider, isAuthenticated)),
-
Widget _buildBody(FeedProvider feedProvider, bool isAuthenticated) {
-
if (feedProvider.isLoading) {
child: CircularProgressIndicator(color: Color(0xFFFF6B35)),
-
if (feedProvider.error != null) {
padding: const EdgeInsets.all(24),
···
const SizedBox(height: 8),
style: const TextStyle(fontSize: 14, color: Color(0xFFB6C2D2)),
textAlign: TextAlign.center,
const SizedBox(height: 24),
-
onPressed: () => feedProvider.retry(),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFFF6B35),
···
-
if (feedProvider.posts.isEmpty) {
padding: const EdgeInsets.all(24),
···
color: const Color(0xFFFF6B35),
controller: _scrollController,
-
feedProvider.posts.length + (feedProvider.isLoadingMore ? 1 : 0),
itemBuilder: (context, index) {
-
if (index == feedProvider.posts.length) {
padding: EdgeInsets.all(16),
···
-
final post = feedProvider.posts[index];
'Feed post in ${post.post.community.name} by ${post.post.author.displayName ?? post.post.author.handle}. ${post.post.title ?? ""}',
···
···
Widget build(BuildContext context) {
+
// Optimized: Use select to only rebuild when specific fields change
+
// This prevents unnecessary rebuilds when unrelated provider fields change
final isAuthenticated = context.select<AuthProvider, bool>(
(p) => p.isAuthenticated,
+
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>>(
+
final isLoadingMore = context.select<FeedProvider, bool>(
+
(p) => p.isLoadingMore,
backgroundColor: const Color(0xFF0B0F14),
···
title: Text(isAuthenticated ? 'Feed' : 'Explore'),
automaticallyImplyLeading: false,
+
isLoadingMore: isLoadingMore,
+
isAuthenticated: isAuthenticated,
+
required bool isLoading,
+
required String? error,
+
required List<FeedViewPost> posts,
+
required bool isLoadingMore,
+
required bool isAuthenticated,
child: CircularProgressIndicator(color: Color(0xFFFF6B35)),
padding: const EdgeInsets.all(24),
···
const SizedBox(height: 8),
+
_getUserFriendlyError(error),
style: const TextStyle(fontSize: 14, color: Color(0xFFB6C2D2)),
textAlign: TextAlign.center,
const SizedBox(height: 24),
+
final feedProvider = Provider.of<FeedProvider>(
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFFF6B35),
···
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),
···
+
final post = posts[index];
'Feed post in ${post.post.community.name} by ${post.post.author.displayName ?? post.post.author.handle}. ${post.post.title ?? ""}',
···
+
/// Transform technical error messages into user-friendly ones
+
String _getUserFriendlyError(String error) {
+
final lowerError = error.toLowerCase();
+
if (lowerError.contains('socketexception') ||
+
lowerError.contains('network') ||
+
lowerError.contains('connection refused')) {
+
return 'Please check your internet connection';
+
} else if (lowerError.contains('timeoutexception') ||
+
lowerError.contains('timeout')) {
+
return 'Request timed out. Please try again';
+
} else if (lowerError.contains('401') ||
+
lowerError.contains('unauthorized')) {
+
return 'Authentication failed. Please sign in again';
+
} else if (lowerError.contains('404') || lowerError.contains('not found')) {
+
return 'Content not found';
+
} else if (lowerError.contains('500') ||
+
lowerError.contains('internal server')) {
+
return 'Server error. Please try again later';
+
// Fallback to generic message for unknown errors
+
return 'Something went wrong. Please try again';