first commit
This commit is contained in:
117
lib/features/feed/presentation/widgets/post_card.dart
Normal file
117
lib/features/feed/presentation/widgets/post_card.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../../../core/theme/app_colors.dart';
|
||||
import '../../../../core/widgets/riotz_card.dart';
|
||||
import '../../domain/models/feed_post_model.dart';
|
||||
|
||||
class PostCard extends StatelessWidget {
|
||||
const PostCard({
|
||||
required this.post,
|
||||
required this.isOwnPost,
|
||||
required this.onLike,
|
||||
required this.onDelete,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final FeedPostModel post;
|
||||
final bool isOwnPost;
|
||||
final VoidCallback onLike;
|
||||
final VoidCallback onDelete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final timeStr = DateFormat('HH:mm // dd.MM.yy').format(post.createdAt);
|
||||
|
||||
return RiotzCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLight,
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: post.avatarUrl.isNotEmpty
|
||||
? CachedNetworkImage(
|
||||
imageUrl: post.avatarUrl,
|
||||
fit: BoxFit.cover,
|
||||
errorWidget: (_, __, ___) => const Icon(Icons.person, color: AppColors.grey),
|
||||
)
|
||||
: const Icon(Icons.person, color: AppColors.grey),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(post.username.toUpperCase(), style: theme.textTheme.labelLarge),
|
||||
Text(timeStr, style: theme.textTheme.bodySmall),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (isOwnPost)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, color: AppColors.grey, size: 20),
|
||||
onPressed: onDelete,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Visuals
|
||||
CachedNetworkImage(
|
||||
imageUrl: post.imageUrl,
|
||||
width: double.infinity,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
height: 300,
|
||||
color: AppColors.surfaceLight,
|
||||
child: const Center(child: CircularProgressIndicator(color: AppColors.neonRed)),
|
||||
),
|
||||
),
|
||||
|
||||
// Footer
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: onLike,
|
||||
icon: Icon(
|
||||
post.isLiked ? Icons.favorite : Icons.favorite_border,
|
||||
color: post.isLiked ? AppColors.neonRed : AppColors.white,
|
||||
),
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text('${post.likesCount}', style: theme.textTheme.titleMedium),
|
||||
const SizedBox(width: 24),
|
||||
const Icon(Icons.chat_bubble_outline, color: AppColors.white, size: 20),
|
||||
],
|
||||
),
|
||||
if (post.caption.isNotEmpty) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text(post.caption, style: theme.textTheme.bodyLarge),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user