forked from eatvio/eatvio_app
150 lines
5.5 KiB
Dart
150 lines
5.5 KiB
Dart
import 'package:eatvio_app/core/locator_service.dart';
|
|
import 'package:eatvio_app/core/utils/date_time_utils.dart';
|
|
import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/profile_avatar_cubit/profile_avatar_cubit.dart';
|
|
import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/profile_avatar_cubit/profile_avatar_state.dart';
|
|
import 'package:eatvio_app/features/feed/models/comment_model.dart';
|
|
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
|
import 'package:eatvio_app/features/feed/presentation/bloc/comments_cubit/comments_cubit.dart';
|
|
import 'package:eatvio_app/generated/l10n.dart';
|
|
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
enum CommentSourceType { blogPost, recipe, diet, plan }
|
|
|
|
class CommentsWidget extends StatefulWidget {
|
|
final String id;
|
|
final CommentSourceType commentSourceType;
|
|
final CommentModel comment;
|
|
final int? replyId;
|
|
|
|
const CommentsWidget({
|
|
super.key,
|
|
required this.id,
|
|
required this.commentSourceType,
|
|
required this.comment,
|
|
this.replyId,
|
|
});
|
|
|
|
@override
|
|
State<CommentsWidget> createState() => _CommentsWidgetState();
|
|
}
|
|
|
|
class _CommentsWidgetState extends State<CommentsWidget> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final s = S.of(context);
|
|
return Column(
|
|
children: [
|
|
for (int i = 0; i < widget.comment.data.length; i++) ...[
|
|
_comment(s, widget.comment.data[i]),
|
|
if (widget.comment.data[i].childrenComments.isNotEmpty) const SizedBox(height: 8),
|
|
for (int j = 0; j < widget.comment.data[i].childrenComments.length; j++)
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 40),
|
|
child: _comment(s, widget.comment.data[i].childrenComments[j], 16, true),
|
|
),
|
|
const SizedBox(height: 8),
|
|
],
|
|
const SizedBox(height: 48),
|
|
],
|
|
);
|
|
}
|
|
|
|
_comment(S s, Comment comment, [double radius = 18, bool isChild = false]) {
|
|
return Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
decoration: BoxDecoration(
|
|
color: widget.replyId == comment.id ? appTheme.blueA400.withValues(alpha: 0.1) : Colors.white,
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
GoRouter.of(context).pushNamed(
|
|
'profileScreen',
|
|
extra: Author(
|
|
authorSlug: comment.authorSlug,
|
|
authorName: comment.authorName,
|
|
authorProfileIcon: comment.authorProfileIcon,
|
|
authorIsMe: (sl<ProfileAvatarCubit>().state as ProfileAvatarStateLoaded).profile.slug == comment.authorSlug ? true : false,
|
|
),
|
|
);
|
|
},
|
|
child: CircleAvatar(
|
|
foregroundImage: NetworkImage(comment.authorProfileIcon),
|
|
backgroundImage: const AssetImage('assets/images/no_avatar.png'),
|
|
radius: radius,
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
comment.authorName,
|
|
style: TextStyle(
|
|
height: 1,
|
|
color: appTheme.gray,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
SizedBox(
|
|
width: isChild ? MediaQuery.of(context).size.width * 0.72 : MediaQuery.of(context).size.width * 0.8,
|
|
child: Text(
|
|
comment.body,
|
|
style: TextStyle(
|
|
height: 1,
|
|
color: appTheme.black,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Row(
|
|
children: [
|
|
Text(
|
|
comment.createdAt.format('dd MMMM', 'ru'),
|
|
style: TextStyle(
|
|
height: 1,
|
|
color: appTheme.gray,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
const SizedBox(width: 16),
|
|
if (!isChild)
|
|
GestureDetector(
|
|
onTap: () {
|
|
context.read<CommentsCubit>().setReplyId(comment.id);
|
|
},
|
|
child: Text(
|
|
s.answer,
|
|
style: TextStyle(
|
|
height: 1,
|
|
color: appTheme.gray,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|