forked from eatvio/eatvio_app
536 lines
20 KiB
Dart
536 lines
20 KiB
Dart
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' as Diets;
|
|
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/locator_service.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
class AboutDietScreen extends StatefulWidget {
|
|
final Diets.Datum datum;
|
|
late final List<int> selectedIndexes;
|
|
|
|
AboutDietScreen({super.key, required this.datum}) {
|
|
selectedIndexes = List.generate(datum.dailySchedule.length, (_) => 0);
|
|
}
|
|
|
|
@override
|
|
State<AboutDietScreen> createState() => _AboutDietScreenState();
|
|
}
|
|
|
|
class _AboutDietScreenState extends State<AboutDietScreen> {
|
|
final CommentsCubit commentsCubit = sl<CommentsCubit>();
|
|
int? replyId;
|
|
final textEditingController = TextEditingController();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
commentsCubit.getDietsComments(widget.datum.id);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocProvider<CommentsCubit>(
|
|
create: (BuildContext context) => commentsCubit,
|
|
child: BlocBuilder<CommentsCubit, CommentsState>(
|
|
builder: (BuildContext context, CommentsState state) {
|
|
return Scaffold(
|
|
resizeToAvoidBottomInset: true,
|
|
bottomSheet: Container(
|
|
padding: EdgeInsets.symmetric(vertical: 12) + (Platform.isIOS ? const EdgeInsets.only(bottom: 16) : EdgeInsets.zero),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
border: Border(
|
|
top: BorderSide(
|
|
color: Colors.black.withOpacity(0.1),
|
|
),
|
|
),
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SizedBox(
|
|
width: MediaQuery.of(context).size.width - 24,
|
|
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,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 8),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
if (replyId != null)
|
|
GestureDetector(
|
|
onTap: () {
|
|
setState(() {
|
|
replyId = null;
|
|
textEditingController.clear();
|
|
});
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
},
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: appTheme.blueA400,
|
|
shape: BoxShape.circle,
|
|
),
|
|
height: 32,
|
|
width: 32,
|
|
child: Icon(
|
|
Icons.close_rounded,
|
|
size: 18,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
if (replyId != null) SizedBox(width: 8),
|
|
SizedBox(
|
|
width: MediaQuery.of(context).size.width - (replyId == null ? 64 : 104),
|
|
child: TextFormField(
|
|
onChanged: (_) {
|
|
setState(() {});
|
|
},
|
|
controller: textEditingController,
|
|
maxLines: 5,
|
|
minLines: 1,
|
|
keyboardType: TextInputType.multiline,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w400,
|
|
color: Colors.black,
|
|
height: 1,
|
|
),
|
|
decoration: InputDecoration(
|
|
isDense: true,
|
|
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
hintText: 'Комментарий',
|
|
hintStyle: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w400,
|
|
height: 1,
|
|
color: Color(0xFFAEAEB2),
|
|
),
|
|
filled: true,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide(
|
|
color: Color(0xFFD1D1D6),
|
|
width: 1,
|
|
),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide(
|
|
color: Color(0xFFD1D1D6),
|
|
width: 1,
|
|
),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide(
|
|
color: Color(0xFFD1D1D6),
|
|
width: 1,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(width: 8),
|
|
GestureDetector(
|
|
onTap: () {
|
|
if (textEditingController.text.length > 2) {
|
|
commentsCubit.sendDietsComment(
|
|
id: widget.datum.id,
|
|
commentText: textEditingController.text,
|
|
parentCommentId: replyId,
|
|
);
|
|
setState(() {
|
|
textEditingController.clear();
|
|
replyId = null;
|
|
});
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
}
|
|
},
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: textEditingController.text.length > 2 ? appTheme.blueA400 : Colors.grey,
|
|
shape: BoxShape.circle,
|
|
),
|
|
height: 32,
|
|
width: 32,
|
|
child: Icon(
|
|
Icons.send_rounded,
|
|
size: 18,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// 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(
|
|
borderRadius: BorderRadius.circular(16),
|
|
onTap: () => GoRouter.of(context).pushNamed('profileScreen', extra: widget.datum.author),
|
|
child: Ink(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
CircleAvatar(
|
|
maxRadius: 16,
|
|
minRadius: 16,
|
|
backgroundImage: NetworkImage(widget.datum.author.authorProfileIcon),
|
|
),
|
|
SizedBox(height: 4),
|
|
Text(
|
|
widget.datum.author.authorName,
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w400,
|
|
height: 1,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: EdgeInsets.only(bottom: 160),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Text(
|
|
widget.datum.name,
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.w500,
|
|
height: 1,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 12),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Row(
|
|
children: [
|
|
Icon(Icons.timer_outlined),
|
|
SizedBox(width: 4),
|
|
Text(
|
|
widget.datum.duration.toString() + ' дней',
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w400,
|
|
height: 1,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: 12),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Text(
|
|
widget.datum.details,
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w400,
|
|
height: 1.2,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 12),
|
|
CachedNetworkImage(
|
|
imageUrl: baseUrl + '/storage/' + widget.datum.image,
|
|
),
|
|
SizedBox(height: 12),
|
|
ListView.separated(
|
|
padding: EdgeInsets.all(16),
|
|
physics: NeverScrollableScrollPhysics(),
|
|
shrinkWrap: true,
|
|
itemBuilder: (context, index) {
|
|
return _dayOfPlan(widget.datum.dailySchedule[index], index);
|
|
},
|
|
separatorBuilder: (context, index) => Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
child: Container(
|
|
height: 0.4,
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey,
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
),
|
|
),
|
|
itemCount: widget.datum.dailySchedule.length,
|
|
),
|
|
SizedBox(height: 32),
|
|
Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 16),
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(
|
|
widget.datum.totalComments.toString() + ' КОММЕНТАРИЕВ',
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: appTheme.gray500,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 16),
|
|
if (state is CommentsStateLoading)
|
|
Padding(
|
|
padding: const EdgeInsets.all(32),
|
|
child: CupertinoActivityIndicator(),
|
|
),
|
|
if (state is CommentsStateLoaded) _buildComments(state.comment),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
_dayOfPlan(List<List<Diets.DailySchedule>> day, int dayNumber) {
|
|
_choiceChipWidget(int index) {
|
|
return ChoiceChip(
|
|
selectedColor: appTheme.blueA400,
|
|
pressElevation: 0,
|
|
showCheckmark: false,
|
|
side: BorderSide.none,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
label: Text((index + 1).toString()),
|
|
labelStyle: TextStyle(
|
|
color: index == widget.selectedIndexes[dayNumber] ? Colors.white : appTheme.gray600,
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: 12,
|
|
),
|
|
selected: widget.selectedIndexes[dayNumber] == index,
|
|
backgroundColor: appTheme.gray100,
|
|
onSelected: (bool selected) {
|
|
setState(() {
|
|
widget.selectedIndexes[dayNumber] = index;
|
|
});
|
|
},
|
|
);
|
|
}
|
|
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'День ' + (dayNumber + 1).toString(),
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w500,
|
|
height: 1,
|
|
),
|
|
),
|
|
SizedBox(height: 4),
|
|
Text(
|
|
'Приём пищи',
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w400,
|
|
height: 1,
|
|
),
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
_choiceChipWidget(0),
|
|
_choiceChipWidget(1),
|
|
_choiceChipWidget(2),
|
|
_choiceChipWidget(3),
|
|
_choiceChipWidget(4),
|
|
],
|
|
),
|
|
SizedBox(height: 8),
|
|
ListView.separated(
|
|
shrinkWrap: true,
|
|
physics: NeverScrollableScrollPhysics(),
|
|
itemBuilder: (context, index) => _daily(day[widget.selectedIndexes[dayNumber]][index]),
|
|
separatorBuilder: (context, index) => SizedBox(height: 4),
|
|
itemCount: day[widget.selectedIndexes[dayNumber]].length,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
_daily(Diets.DailySchedule daily) {
|
|
return Row(
|
|
children: [
|
|
Text(
|
|
'• ' + daily.name,
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w400,
|
|
height: 1.2,
|
|
),
|
|
),
|
|
Spacer(),
|
|
Text(
|
|
daily.quantity.toString() + ' ' + daily.portion.name,
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w400,
|
|
height: 1.2,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
_buildComments(Comment 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(Datum datum, [double radius = 16]) {
|
|
return Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
decoration: BoxDecoration(
|
|
color: replyId == datum.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(datum.authorProfileIcon),
|
|
radius: radius,
|
|
),
|
|
SizedBox(width: 8),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
datum.authorName,
|
|
style: TextStyle(
|
|
height: 1,
|
|
color: Colors.grey.shade600,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
SizedBox(width: 4),
|
|
Text(
|
|
datum.body,
|
|
style: TextStyle(
|
|
height: 1,
|
|
color: Colors.black,
|
|
),
|
|
),
|
|
SizedBox(height: 4),
|
|
Row(
|
|
children: [
|
|
Text(
|
|
'99 августа',
|
|
// datum.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 = datum.id;
|
|
});
|
|
},
|
|
child: Text(
|
|
'Ответить',
|
|
style: TextStyle(
|
|
height: 1,
|
|
fontSize: 12,
|
|
color: Colors.grey.shade800,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|