import 'package:eatvio_app/core/utils/pagination_utils.dart'; import 'package:eatvio_app/core/widgets/data_error_widget.dart'; import 'package:eatvio_app/core/widgets/loader.dart'; import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_cubit.dart'; import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_state.dart'; import 'package:eatvio_app/features/feed/presentation/widgets/blog_post_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class BlogPosts extends StatelessWidget { const BlogPosts({super.key}); @override Widget build(BuildContext context) { return RefreshIndicator( onRefresh: () => context.read().loadFeedBlogPostList(), child: BlocBuilder( builder: (BuildContext context, FeedState state) { if (state is FeedStateLoaded) { return NotificationListener( onNotification: (notification) { loadNewContent(notification, context.read().loadNextPage); return false; }, child: ListView.separated( padding: const EdgeInsets.symmetric(vertical: 8), physics: const BouncingScrollPhysics(), itemBuilder: (context, index) { if (index == state.feedBlogPostList.length) { return const Loader(); } return BlogPostWidget(index: index); }, separatorBuilder: (context, index) => const SizedBox(height: 8), itemCount: state.isLoading ? state.feedBlogPostList.length + 1 : state.feedBlogPostList.length, ), ); } else if (state is FeedStateError) { return DataErrorWidget( onReload: () => context.read().loadFeedBlogPostList(), ); } else { return Scaffold( backgroundColor: Colors.grey.shade200, body: const Loader(), ); } }, ), ); } }