refactoring
This commit is contained in:
101
lib/presentation/screens/social/social_card.dart
Normal file
101
lib/presentation/screens/social/social_card.dart
Normal file
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/constants/colors.dart';
|
||||
import '../../../data/models/social_post_model.dart';
|
||||
import '../../widgets/social_header_widget.dart';
|
||||
import '../../widgets/social_interaction_row.dart';
|
||||
import '../../widgets/swipe_background.dart'; // Import du widget de swipe
|
||||
|
||||
class SocialCard extends StatelessWidget {
|
||||
final SocialPost post;
|
||||
final VoidCallback onLike;
|
||||
final VoidCallback onComment;
|
||||
final VoidCallback onShare;
|
||||
final VoidCallback onDeletePost;
|
||||
final VoidCallback onEditPost;
|
||||
|
||||
const SocialCard({
|
||||
Key? key,
|
||||
required this.post,
|
||||
required this.onLike,
|
||||
required this.onComment,
|
||||
required this.onShare,
|
||||
required this.onDeletePost,
|
||||
required this.onEditPost,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Dismissible(
|
||||
key: ValueKey(post.postText),
|
||||
direction: DismissDirection.endToStart,
|
||||
onDismissed: (direction) {
|
||||
onDeletePost();
|
||||
},
|
||||
background: SwipeBackground(
|
||||
color: Colors.red,
|
||||
icon: Icons.delete,
|
||||
label: 'Supprimer',
|
||||
),
|
||||
child: Card(
|
||||
color: AppColors.cardColor,
|
||||
margin: const EdgeInsets.symmetric(vertical: 10.0),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SocialHeaderWidget(
|
||||
post: post,
|
||||
onEditPost: () {
|
||||
print('Modifier le post');
|
||||
},
|
||||
menuKey: GlobalKey(),
|
||||
menuContext: context,
|
||||
onClosePost: () {
|
||||
print('Close post');
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text (
|
||||
post.postText,
|
||||
style: TextStyle(
|
||||
color: AppColors.textSecondary,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (post.postImage.isNotEmpty)
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Image.asset(post.postImage, fit: BoxFit.cover),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: post.tags
|
||||
.map((tag) => Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: Text(
|
||||
tag,
|
||||
style: TextStyle(
|
||||
color: AppColors.accentColor,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SocialInteractionRow(
|
||||
post: post,
|
||||
onLike: onLike,
|
||||
onComment: onComment,
|
||||
onShare: onShare,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
103
lib/presentation/screens/social/social_content.dart
Normal file
103
lib/presentation/screens/social/social_content.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../data/models/social_post_model.dart';
|
||||
import 'social_card.dart'; // Import de la SocialCard
|
||||
|
||||
class SocialContent extends StatefulWidget {
|
||||
const SocialContent({super.key});
|
||||
|
||||
@override
|
||||
_SocialContentState createState() => _SocialContentState();
|
||||
}
|
||||
|
||||
class _SocialContentState extends State<SocialContent> {
|
||||
final List<SocialPost> _posts = [
|
||||
SocialPost(
|
||||
userName: 'John Doe',
|
||||
userImage: 'lib/assets/images/profile_picture.png',
|
||||
postText: 'Une belle journée au parc avec des amis ! 🌳🌞',
|
||||
postImage: 'lib/assets/images/placeholder.png',
|
||||
likes: 12,
|
||||
comments: 4,
|
||||
badges: ['Explorer', 'Photographe'],
|
||||
tags: ['#Nature', '#FunDay'],
|
||||
shares: 25,
|
||||
),
|
||||
SocialPost(
|
||||
userName: 'Jane Smith',
|
||||
userImage: 'lib/assets/images/profile_picture.png',
|
||||
postText: 'Mon nouveau chat est tellement mignon 🐱',
|
||||
postImage: 'lib/assets/images/placeholder.png',
|
||||
likes: 30,
|
||||
comments: 8,
|
||||
badges: ['Animal Lover', 'Partageur'],
|
||||
tags: ['#Chat', '#Cuteness'],
|
||||
shares: 25,
|
||||
),
|
||||
SocialPost(
|
||||
userName: 'Alice Brown',
|
||||
userImage: 'lib/assets/images/profile_picture.png',
|
||||
postText: 'Café du matin avec une vue magnifique ☕️',
|
||||
postImage: 'lib/assets/images/placeholder.png',
|
||||
likes: 45,
|
||||
comments: 15,
|
||||
badges: ['Gourmet', 'Partageur'],
|
||||
tags: ['#Café', '#MorningVibes'],
|
||||
shares: 25,
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: _posts.length,
|
||||
itemBuilder: (context, index) {
|
||||
final post = _posts[index];
|
||||
return SocialCard(
|
||||
post: post,
|
||||
onLike: () {
|
||||
setState(() {
|
||||
_posts[index] = SocialPost(
|
||||
userName: post.userName,
|
||||
userImage: post.userImage,
|
||||
postText: post.postText,
|
||||
postImage: post.postImage,
|
||||
likes: post.likes + 1,
|
||||
comments: post.comments,
|
||||
badges: post.badges,
|
||||
tags: post.tags,
|
||||
shares: post.shares + 1,
|
||||
);
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Like ajouté')),
|
||||
);
|
||||
},
|
||||
onComment: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Commentaire ajouté')),
|
||||
);
|
||||
},
|
||||
onShare: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Post partagé')),
|
||||
);
|
||||
},
|
||||
onDeletePost: () {
|
||||
setState(() {
|
||||
_posts.removeAt(index);
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Post supprimé')),
|
||||
);
|
||||
},
|
||||
onEditPost: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Post modifié')),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'social_content.dart'; // Import du fichier qui contient SocialContent
|
||||
|
||||
class SocialScreen extends StatelessWidget {
|
||||
const SocialScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Text(
|
||||
'Social',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFF1E1E2C), // Fond noir pour correspondre à un thème sombre
|
||||
appBar: AppBar(
|
||||
title: const Text(
|
||||
'Social',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.black, // AppBar avec fond noir pour un design cohérent
|
||||
),
|
||||
body: SocialContent(), // Appel à SocialContent pour afficher le contenu
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user