refactor: scroll

This commit is contained in:
mso7nueh
2024-09-09 12:58:25 +03:00
parent f9c10047b2
commit 3ccf5b6d92
31 changed files with 610 additions and 608 deletions

View File

@@ -1,12 +1,11 @@
import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:eatvio_app/core/app_export.dart';
import 'package:eatvio_app/features/feed/models/comment_model.dart';
import 'package:eatvio_app/features/feed/models/recipes_model.dart' as step;
import 'package:eatvio_app/features/feed/models/recipes_model.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/comments_cubit/comments_cubit.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/comments_cubit/comments_state.dart';
import 'package:eatvio_app/features/feed/presentation/widgets/comments_widget.dart';
import 'package:eatvio_app/locator_service.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -26,21 +25,24 @@ class _AboutRecipesScreenState extends State<AboutRecipesScreen> {
final textEditingController = TextEditingController();
int? replyId;
@override
void initState() {
super.initState();
commentsCubit.getRecipesComments(widget.recipes.slug);
}
@override
Widget build(BuildContext context) {
return BlocProvider<CommentsCubit>(
create: (BuildContext context) => commentsCubit,
child: BlocBuilder<CommentsCubit, CommentsState>(
builder: (BuildContext context, CommentsState state) {
if (state is CommentsStateError) {
print(state.errorMessage);
create: (BuildContext context) => commentsCubit
..getComments(
widget.recipes.slug,
CommentSourceType.recipe,
true,
),
child: BlocConsumer<CommentsCubit, CommentsState>(
listener: (BuildContext context, CommentsState state) {
if (state is CommentsStateLoaded) {
setState(() {
replyId = state.replyId;
});
}
},
builder: (BuildContext context, CommentsState state) {
return Scaffold(
resizeToAvoidBottomInset: true,
bottomSheet: Container(
@@ -59,6 +61,7 @@ class _AboutRecipesScreenState extends State<AboutRecipesScreen> {
if (replyId != null)
GestureDetector(
onTap: () {
context.read<CommentsCubit>().setReplyId(null);
setState(() {
replyId = null;
textEditingController.clear();
@@ -81,7 +84,7 @@ class _AboutRecipesScreenState extends State<AboutRecipesScreen> {
),
if (replyId != null) SizedBox(width: 8),
SizedBox(
width: mediaQueryData.size.width - (replyId == null ? 64 : 104),
width: MediaQuery.of(context).size.width - (replyId == null ? 64 : 104),
child: TextFormField(
onChanged: (_) {
setState(() {});
@@ -135,11 +138,13 @@ class _AboutRecipesScreenState extends State<AboutRecipesScreen> {
GestureDetector(
onTap: () {
if (textEditingController.text.length > 2) {
commentsCubit.sendRecipesComment(
commentsCubit.sendComment(
id: widget.recipes.slug,
commentText: textEditingController.text,
parentCommentId: replyId,
commentSourceType: CommentSourceType.recipe,
);
context.read<CommentsCubit>().setReplyId(null);
setState(() {
textEditingController.clear();
replyId = null;
@@ -300,17 +305,16 @@ class _AboutRecipesScreenState extends State<AboutRecipesScreen> {
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) => _step(widget.recipes.steps[index], index + 1),
separatorBuilder: (context, index) =>
Padding(
padding: const EdgeInsets.all(16),
child: Container(
height: 0.4,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.circular(16),
),
),
separatorBuilder: (context, index) => Padding(
padding: const EdgeInsets.all(16),
child: Container(
height: 0.4,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.circular(16),
),
),
),
itemCount: widget.recipes.steps.length,
),
SizedBox(height: 8),
@@ -343,7 +347,13 @@ class _AboutRecipesScreenState extends State<AboutRecipesScreen> {
padding: const EdgeInsets.all(32),
child: CupertinoActivityIndicator(),
),
if (state is CommentsStateLoaded) _buildComments(state.comment),
if (state is CommentsStateLoaded)
CommentsWidget(
id: widget.recipes.slug,
commentSourceType: CommentSourceType.recipe,
comment: state.comment,
replyId: replyId,
),
],
),
),
@@ -406,103 +416,4 @@ class _AboutRecipesScreenState extends State<AboutRecipesScreen> {
],
);
}
_buildComments(CommentModel comment) {
return Column(
children: [
for (int i = 0; i < comment.data.length; i++) ...[
_comment(comment.data[i]),
if (comment.data[i].childrenComments.isNotEmpty)
for (int j = 0; j < comment.data[i].childrenComments.length; j++)
Padding(
padding: EdgeInsets.only(left: 40),
child: _comment(
comment.data[i].childrenComments[j],
12,
),
),
SizedBox(height: 8),
],
],
);
}
_comment(Comment comment, [double radius = 16]) {
return Container(
width: MediaQuery
.of(context)
.size
.width,
decoration: BoxDecoration(
color: replyId == comment.id ? appTheme.blueA400.withOpacity(0.1) : Colors.white,
borderRadius: BorderRadius.circular(16),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
foregroundImage: NetworkImage(comment.authorProfileIcon),
radius: radius,
),
SizedBox(width: 8),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
comment.authorName,
style: TextStyle(
height: 1,
color: Colors.grey.shade600,
fontWeight: FontWeight.w500,
),
),
SizedBox(width: 4),
Text(
comment.body,
style: TextStyle(
height: 1,
color: Colors.black,
),
),
SizedBox(height: 4),
Row(
children: [
Text(
comment.createdAt.format('dd MMMM', 'ru'),
style: TextStyle(
color: Colors.grey.shade600,
fontSize: 12,
fontWeight: FontWeight.w400,
height: 1,
),
),
SizedBox(width: 16),
GestureDetector(
onTap: () {
setState(() {
replyId = comment.id;
});
},
child: Text(
'Ответить',
style: TextStyle(
height: 1,
fontSize: 12,
color: Colors.grey.shade800,
fontWeight: FontWeight.w500,
),
),
),
],
),
],
),
],
),
),
);
}
}