first commit
This commit is contained in:
94
lib/features/feed/presentation/screens/feed_screen.dart
Normal file
94
lib/features/feed/presentation/screens/feed_screen.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../../core/router/app_routes.dart';
|
||||
import '../../../../core/theme/app_colors.dart';
|
||||
import '../../../../core/widgets/riotz_scaffold.dart';
|
||||
import '../../../auth/presentation/providers/auth_provider.dart';
|
||||
import '../providers/post_providers.dart';
|
||||
import '../widgets/post_card.dart';
|
||||
|
||||
class FeedScreen extends ConsumerWidget {
|
||||
const FeedScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final postsAsync = ref.watch(feedPostsProvider);
|
||||
final currentUser = ref.watch(authServiceProvider).currentUser;
|
||||
|
||||
return RiotzScaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('RIOTZ // FEED'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add_box_outlined, color: AppColors.white),
|
||||
onPressed: () => context.push(AppRoutes.uploadPost),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
color: AppColors.neonRed,
|
||||
backgroundColor: AppColors.black,
|
||||
onRefresh: () async => ref.refresh(feedPostsProvider),
|
||||
child: postsAsync.when(
|
||||
data: (posts) {
|
||||
if (posts.isEmpty) {
|
||||
return const Center(
|
||||
child: Text('NO CHAOS YET. START A RIOT.'),
|
||||
);
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: posts.length,
|
||||
itemBuilder: (context, index) {
|
||||
final post = posts[index];
|
||||
return PostCard(
|
||||
post: post,
|
||||
isOwnPost: post.userId == currentUser?.id,
|
||||
onLike: () => ref.read(postControllerProvider.notifier).toggleLike(post),
|
||||
onDelete: () => _confirmDelete(context, ref, post.id),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
loading: () => const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.neonRed),
|
||||
),
|
||||
error: (error, _) => Center(
|
||||
child: Text('SIGNAL LOST: $error'),
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
backgroundColor: AppColors.neonRed,
|
||||
child: const Icon(Icons.add, color: AppColors.white),
|
||||
onPressed: () => context.push(AppRoutes.uploadPost),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _confirmDelete(BuildContext context, WidgetRef ref, String postId) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: AppColors.surface,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
|
||||
title: const Text('ERASE TRANSMISSION?'),
|
||||
content: const Text('THIS ACTION CANNOT BE UNDONE.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('CANCEL', style: TextStyle(color: AppColors.white)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
ref.read(postControllerProvider.notifier).deletePost(postId);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('DELETE', style: TextStyle(color: AppColors.neonRed)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user