import 'package:cached_network_image/cached_network_image.dart'; import 'package:eatvio_app/core/constants/constants.dart'; import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart'; import 'package:eatvio_app/theme/theme_helper.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; class AboutDietScreen extends StatefulWidget { final Datum datum; late final List selectedIndexes; AboutDietScreen({super.key, required this.datum}) { selectedIndexes = List.generate(datum.dailySchedule.length, (_) => 0); } @override State createState() => _AboutDietScreenState(); } class _AboutDietScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( 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: 80), 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), ], ), ), ); } _dayOfPlan(List> 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(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, ), ), ], ); } }