forked from eatvio/eatvio_app
refactor: scroll
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
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/diets_pagination_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';
|
||||
@@ -28,17 +27,23 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
|
||||
int? replyId;
|
||||
final textEditingController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
commentsCubit.getDietsComments(widget.diet.id);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<CommentsCubit>(
|
||||
create: (BuildContext context) => commentsCubit,
|
||||
child: BlocBuilder<CommentsCubit, CommentsState>(
|
||||
create: (BuildContext context) => commentsCubit
|
||||
..getComments(
|
||||
widget.diet.id.toString(),
|
||||
CommentSourceType.diet,
|
||||
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,
|
||||
@@ -80,6 +85,7 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
|
||||
if (replyId != null)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<CommentsCubit>().setReplyId(null);
|
||||
setState(() {
|
||||
replyId = null;
|
||||
textEditingController.clear();
|
||||
@@ -156,11 +162,13 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (textEditingController.text.length > 2) {
|
||||
commentsCubit.sendDietsComment(
|
||||
id: widget.diet.id,
|
||||
commentsCubit.sendComment(
|
||||
id: widget.diet.id.toString(),
|
||||
commentText: textEditingController.text,
|
||||
parentCommentId: replyId,
|
||||
commentSourceType: CommentSourceType.diet,
|
||||
);
|
||||
context.read<CommentsCubit>().setReplyId(null);
|
||||
setState(() {
|
||||
textEditingController.clear();
|
||||
replyId = null;
|
||||
@@ -187,25 +195,6 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
// floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||||
// floatingActionButton: SizedBox(
|
||||
// width: MediaQuery.of(context).size.width - 32,
|
||||
// child: FloatingActionButton.extended(
|
||||
// heroTag: 'nextButtonRegistration',
|
||||
// highlightElevation: 0,
|
||||
// elevation: 0,
|
||||
// focusElevation: 0,
|
||||
// shape: RoundedRectangleBorder(
|
||||
// borderRadius: BorderRadius.circular(16),
|
||||
// ),
|
||||
// backgroundColor: appTheme.greenA700,
|
||||
// onPressed: () {},
|
||||
// label: Text(
|
||||
// 'Начать диету',
|
||||
// style: theme.textTheme.titleSmall,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
appBar: AppBar(
|
||||
actions: [
|
||||
InkWell(
|
||||
@@ -340,7 +329,13 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: CupertinoActivityIndicator(),
|
||||
),
|
||||
if (state is CommentsStateLoaded) _buildComments(state.comment),
|
||||
if (state is CommentsStateLoaded)
|
||||
CommentsWidget(
|
||||
id: widget.diet.id.toString(),
|
||||
commentSourceType: CommentSourceType.diet,
|
||||
comment: state.comment,
|
||||
replyId: replyId,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -446,100 +441,4 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
_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 diet, [double radius = 16]) {
|
||||
return Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
decoration: BoxDecoration(
|
||||
color: replyId == diet.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(diet.authorProfileIcon),
|
||||
radius: radius,
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
diet.authorName,
|
||||
style: TextStyle(
|
||||
height: 1,
|
||||
color: Colors.grey.shade600,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Text(
|
||||
diet.body,
|
||||
style: TextStyle(
|
||||
height: 1,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
diet.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 = diet.id;
|
||||
});
|
||||
},
|
||||
child: Text(
|
||||
'Ответить',
|
||||
style: TextStyle(
|
||||
height: 1,
|
||||
fontSize: 12,
|
||||
color: Colors.grey.shade800,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user