Skip to content

Commit

Permalink
문자 AppString.dart에서 import 해서 쓰도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ottuck committed Aug 31, 2024
1 parent 11237ff commit 7feca65
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 252 deletions.
128 changes: 74 additions & 54 deletions lib/feature/post/widget/CommentBottomSheetWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../provider/CommentProvider.dart';
import '../provider/UserInfoProvider.dart';

class CommentBottomSheetWidget extends ConsumerWidget {
final String postID;
Expand All @@ -16,65 +17,84 @@ class CommentBottomSheetWidget extends ConsumerWidget {
final TextEditingController commentController = TextEditingController();
const userID = 'eztqDqrvEXDc8nqnnrB8'; // 임시 사용자 ID

return FractionallySizedBox(
heightFactor: 0.75, // 모달의 높이를 75%로 설정
child: Padding(
padding: const EdgeInsets.all(16.0), // 패딩 추가
child: Column(
children: [
// '댓글' 제목
const Text(
'댓글',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8), // 제목과 댓글 리스트 사이 간격
// 댓글 리스트
Expanded(
child: commentList.when(
data: (comments) {
return ListView.builder(
itemCount: comments.length,
itemBuilder: (context, index) {
final comment = comments[index];
return CommentItemWidget(comment: comment);
},
);
},
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stackTrace) => Center(child: Text('Error: $error')),
),
),
const SizedBox(height: 8), // 댓글 리스트와 입력 필드 사이 간격
// 댓글 입력 필드
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0), // 입력 필드의 좌우 패딩
child: TextField(
controller: commentController,
decoration: InputDecoration(
hintText: '댓글 추가...',
suffixIcon: IconButton(
icon: const Icon(Icons.send),
onPressed: () async {
final content = commentController.text.trim();
if (content.isNotEmpty) {
await commentNotifier.addComment(content, userID);
commentController.clear();
}
final postUserInfo = ref.watch(postUserInfoProvider(userID));

return postUserInfo.when(
data: (userInfo) {
return FractionallySizedBox(
heightFactor: 0.75, // 모달의 높이를 75%로 설정
child: Padding(
padding: const EdgeInsets.all(16.0), // 패딩 추가
child: Column(
children: [
// '댓글' 제목
const Text(
'댓글',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8), // 제목과 댓글 리스트 사이 간격
// 댓글 리스트
Expanded(
child: commentList.when(
data: (comments) {
return ListView.builder(
itemCount: comments.length,
itemBuilder: (context, index) {
final comment = comments[index];
return CommentItemWidget(
comment: comment,
userName: userInfo.name,
userProfileImageUrl: userInfo.profileImageUrl,
postID: postID,
onDelete: (commentID) async {
await commentNotifier.deleteComment(commentID);
},
onEdit: (commentID, newContent) async {
await commentNotifier.updateComment(commentID, newContent);
},
);
},
);
},
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stackTrace) => Center(child: Text('Error: $error')),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
),
const SizedBox(height: 8), // 댓글 리스트와 입력 필드 사이 간격
// 댓글 입력 필드
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0), // 입력 필드의 좌우 패딩
child: TextField(
controller: commentController,
decoration: InputDecoration(
hintText: '댓글 추가...',
suffixIcon: IconButton(
icon: const Icon(Icons.send),
onPressed: () async {
final content = commentController.text.trim();
if (content.isNotEmpty) {
await commentNotifier.addComment(content, userID);
commentController.clear();
}
},
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
),
),
),
),
),
],
),
],
),
),
),
);
},
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stackTrace) => const Center(child: Text('Error loading user info')),
);
}
}
Expand Down
209 changes: 106 additions & 103 deletions lib/feature/post/widget/CommentItemWidget.dart
Original file line number Diff line number Diff line change
@@ -1,127 +1,130 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';

import '../../../model/CommentModel.dart';
import '../provider/UserInfoProvider.dart';
import 'DeleteConfirmationDialog.dart';
import 'EditCommentDialog.dart';
import 'DeleteConfirmationDialogWidget.dart';
import 'EditCommentDialogWidget.dart';

class CommentItemWidget extends ConsumerWidget {
class CommentItemWidget extends StatelessWidget {
final CommentModel comment;
final String userName;
final String userProfileImageUrl;
final String postID;
final void Function(String commentID) onDelete;
final void Function(String commentID, String newContent) onEdit;

const CommentItemWidget({super.key, required this.comment});
const CommentItemWidget({
super.key,
required this.comment,
required this.userName,
required this.userProfileImageUrl,
required this.postID,
required this.onDelete,
required this.onEdit,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
final postUserInfo = ref.watch(postUserInfoProvider(comment.userID));
Widget build(BuildContext context) {
final TextEditingController editController = TextEditingController(text: comment.content);

return postUserInfo.when(
data: (userInfo) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
backgroundImage: NetworkImage(userInfo.profileImageUrl),
radius: 20,
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
backgroundImage: NetworkImage(userProfileImageUrl),
radius: 20,
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Row(
children: [
Text(
userInfo.name,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
const SizedBox(width: 8),
Text(
DateFormat.yMMMd().format(comment.createdAt),
style: const TextStyle(
fontSize: 12,
color: Colors.grey,
),
),
const Spacer(),
PopupMenuButton<String>(
icon: const Icon(Icons.more_vert),
onSelected: (value) {
if (value == 'edit') {
showDialog(
context: context,
builder: (context) => EditCommentDialog(
commentID: comment.commentID,
postID: comment.postID,
ref: ref,
editController: editController,
),
);
} else if (value == 'delete') {
showDialog(
context: context,
builder: (context) => DeleteConfirmationDialog(
commentID: comment.commentID,
postID: comment.postID,
ref: ref,
),
);
}
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'edit',
child: Text('수정'),
Text(
userName,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
const SizedBox(width: 8),
Text(
DateFormat.yMMMd().format(comment.createdAt),
style: const TextStyle(
fontSize: 12,
color: Colors.grey,
),
),
const Spacer(),
PopupMenuButton<String>(
icon: const Icon(Icons.more_vert),
onSelected: (value) {
if (value == 'edit') {
showDialog(
context: context,
builder: (context) => EditCommentDialogWidget(
commentID: comment.commentID,
postID: postID,
editController: editController,
onEdit: onEdit, // onEdit 콜백 전달
),
const PopupMenuItem<String>(
value: 'delete',
child: Text('삭제'),
);
} else if (value == 'delete') {
showDialog(
context: context,
builder: (context) => DeleteConfirmationDialogWidget(
commentID: comment.commentID,
onDelete: onDelete, // onDelete 콜백 전달
),
],
),
],
),
const SizedBox(height: 4),
Text(comment.content),
const SizedBox(height: 8),
Row(
children: [
IconButton(
icon: const Icon(Icons.thumb_up_alt_outlined, size: 20),
onPressed: () {
// 좋아요 버튼 기능
},
),
IconButton(
icon: const Icon(Icons.thumb_down_alt_outlined, size: 20),
onPressed: () {
// 싫어요 버튼 기능
},
);
}
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'edit',
child: Text('수정'),
),
IconButton(
icon: const Icon(Icons.comment_outlined, size: 20),
onPressed: () {
// 댓글 버튼 기능
},
const PopupMenuItem<String>(
value: 'delete',
child: Text('삭제'),
),
],
)
],
),
const SizedBox(height: 4),
Text(comment.content),
const SizedBox(height: 8),
Row(
children: [
IconButton(
icon: const Icon(Icons.thumb_up_alt_outlined, size: 20),
onPressed: () {
// 좋아요 버튼 기능
},
),
IconButton(
icon: const Icon(Icons.thumb_down_alt_outlined, size: 20),
onPressed: () {
// 싫어요 버튼 기능
},
),
IconButton(
icon: const Icon(Icons.comment_outlined, size: 20),
onPressed: () {
// 댓글 버튼 기능
},
),
],
),
),
],
],
),
),
);
},
loading: () => const CircularProgressIndicator(),
error: (error, stackTrace) => const Icon(Icons.error),
],
),
);
}
}
Loading

0 comments on commit 7feca65

Please sign in to comment.