forked from eatvio/eatvio_app
56 lines
2.2 KiB
Dart
56 lines
2.2 KiB
Dart
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<FeedCubit>().loadFeedBlogPostList(),
|
|
child: BlocBuilder<FeedCubit, FeedState>(
|
|
builder: (BuildContext context, FeedState state) {
|
|
if (state is FeedStateLoaded) {
|
|
return NotificationListener<ScrollNotification>(
|
|
onNotification: (notification) {
|
|
loadNewContent(notification, context.read<FeedCubit>().loadNextPage);
|
|
return false;
|
|
},
|
|
child: ListView.separated(
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
shrinkWrap: true,
|
|
physics: const BouncingScrollPhysics(),
|
|
itemBuilder: (context, index) {
|
|
if (index == state.feedBlogPostList.length) {
|
|
return const Loader();
|
|
}
|
|
return BlogPostWidget(index: index);
|
|
},
|
|
separatorBuilder: (context, index) {
|
|
return const SizedBox(height: 8);
|
|
},
|
|
itemCount: state.isLoading ? state.feedBlogPostList.length + 1 : state.feedBlogPostList.length,
|
|
),
|
|
);
|
|
} else if (state is FeedStateError) {
|
|
return DataErrorWidget(
|
|
onReload: () => context.read<FeedCubit>().loadFeedBlogPostList(),
|
|
);
|
|
} else {
|
|
return Scaffold(
|
|
backgroundColor: Colors.grey.shade200,
|
|
body: const Loader(),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|