import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart'; import 'package:eatvio_app/features/feed/presentation/widgets/blog_post_widget.dart'; import 'package:eatvio_app/features/profile/models/profile_model.dart'; import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart'; import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_state.dart'; import 'package:eatvio_app/features/profile/presentation/widgets/circumference_chart_widget.dart'; import 'package:eatvio_app/features/profile/presentation/widgets/imt_chart_widget.dart'; import 'package:eatvio_app/features/profile/presentation/widgets/weight_chart_widget.dart'; import 'package:eatvio_app/locator_service.dart'; import 'package:flutter/material.dart'; class ProfileScreen extends StatefulWidget { final Author? author; const ProfileScreen({super.key, this.author}); @override State createState() => _ProfileScreenState(); } class _ProfileScreenState extends State { List chartData = []; List chartPoints = []; final List chipsLabelList = ['Вес', 'Замеры', 'ИМТ']; final List chipsIntervalLabelList = ['1М', '3М', '6М', '1Г', 'ВСЁ ВРЕМЯ']; int _selectedChipIndex = 0; int _selectedIntervalChipIndex = 0; @override Widget build(BuildContext context) { return BlocProvider( create: (BuildContext context) { if (widget.author == null) return sl()..getMyProfile(); else return sl()..getProfileBySlug(widget.author!.authorSlug); }, child: BlocBuilder( builder: (BuildContext context, ProfileState state) { if (state is ProfileStateLoaded) { chartData = state.profile.circumferences; chartPoints = state.profile.chartPoints; return Scaffold( backgroundColor: Colors.grey.shade200, appBar: widget.author == null ? AppBar(toolbarHeight: 0) : AppBar(), body: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.vertical( bottom: Radius.circular(16), ), ), child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Padding( padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16), child: Row( children: [ CircleAvatar( radius: 32, backgroundImage: NetworkImage(state.profile.user.profilePhotoUrl), ), const SizedBox(width: 12), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( state.profile.user.name, style: TextStyle( color: Colors.black, fontWeight: FontWeight.w500, height: 1, ), ), if (state.profile.userDetails.additionalInfo.isNotEmpty) Text( state.profile.userDetails.additionalInfo, style: TextStyle( color: Colors.black.withOpacity(0.4), height: 1, ), ), ], ), ], ), ), if (widget.author == null) _divider(context), if (widget.author == null) Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox(height: 8), SingleChildScrollView( padding: EdgeInsets.symmetric(horizontal: 16), scrollDirection: Axis.horizontal, child: Row( children: [ _choiceChipWidget(0), SizedBox(width: 8), _choiceChipWidget(1), SizedBox(width: 8), _choiceChipWidget(2), ], ), ), Builder( builder: (context) { if (_selectedChipIndex == 0) return WeightChartWidget(chartPoints: chartPoints); if (_selectedChipIndex == 1) return CircumferenceChartWidget(chartData: chartData); if (_selectedChipIndex == 2) return ImtChartWidget(chartPoints: chartPoints); else return Container(); }, ), SizedBox(height: 8), Row( children: [ SizedBox(width: 16), _choiceIntervalChipWidget(0), SizedBox(width: 8), _choiceIntervalChipWidget(1), SizedBox(width: 8), _choiceIntervalChipWidget(2), SizedBox(width: 8), _choiceIntervalChipWidget(3), SizedBox(width: 8), _choiceIntervalChipWidget(4), ], ), SizedBox(height: 8), ], ), ], ), ), SizedBox(height: 16), ListView.separated( shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), itemBuilder: (context, index) => BlogPostWidget(feedBlogPostModel: state.blogPosts[index]), separatorBuilder: (context, index) => SizedBox(height: 8), itemCount: state.blogPosts.length, ), SizedBox(height: 16), ], ), ), ); } else if (state is ProfileStateError) { return Scaffold( appBar: AppBar(), body: Center( child: Padding( padding: const EdgeInsets.all(16), child: Text(state.errorMessage), ), ), ); } else { return Scaffold( appBar: AppBar(), body: Center( child: CircularProgressIndicator(), ), ); } }, ), ); } _divider(BuildContext context) { return Container( height: 0.4, width: MediaQuery.of(context).size.width - 32, decoration: BoxDecoration( color: Colors.black26, borderRadius: BorderRadius.circular(16), ), ); } _choiceIntervalChipWidget(int index) { return ChoiceChip( selectedColor: Colors.grey.withOpacity(0.1), pressElevation: 0, showCheckmark: false, side: BorderSide.none, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), ), padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), label: Text(chipsIntervalLabelList[index]), labelStyle: TextStyle( color: appTheme.gray600, fontWeight: FontWeight.w500, fontSize: 12, ), selected: _selectedIntervalChipIndex == index, onSelected: (bool selected) { setState(() { _selectedIntervalChipIndex = index; }); }, ); } _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: 8, vertical: 4), label: Text(chipsLabelList[index]), labelStyle: TextStyle( color: index == _selectedChipIndex ? Colors.white : appTheme.gray600, fontWeight: FontWeight.w500, fontSize: 12, ), selected: _selectedChipIndex == index, backgroundColor: appTheme.gray100, onSelected: (bool selected) { setState(() { _selectedChipIndex = index; }); }, ); } }