import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/features/feed/models/diets_pagination_model.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/locator_service.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:syncfusion_flutter_charts/charts.dart'; class ProfileScreen extends StatefulWidget { final Author? author; const ProfileScreen({super.key, this.author}); @override State createState() => _ProfileScreenState(); } class _ProfileScreenState extends State { List chartData = []; @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; return Scaffold( appBar: AppBar( centerTitle: false, title: Text(state.profile.user.name), ), body: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.only(left: 16, bottom: 32), child: CircleAvatar( radius: 32, backgroundImage: NetworkImage(state.profile.user.profilePhotoUrl), ), ), SfCartesianChart( margin: EdgeInsets.zero, enableAxisAnimation: true, enableSideBySideSeriesPlacement: true, legend: const Legend( isVisible: true, opacity: 0.7, position: LegendPosition.bottom, ), plotAreaBorderWidth: 0, trackballBehavior: TrackballBehavior( enable: true, activationMode: ActivationMode.singleTap, ), primaryXAxis: DateTimeAxis( dateFormat: DateFormat.MMMd('ru'), axisLine: AxisLine( width: 1, ), ), primaryYAxis: NumericAxis( labelFormat: '{value} см', axisLine: AxisLine( width: 1, ), majorTickLines: MajorTickLines(size: 0), ), series: _getSplineAreaSeries(), tooltipBehavior: TooltipBehavior(enable: true), ), ], ), ), ); } 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(), ), ); } }, ), ); } List> _getSplineAreaSeries() { final Color seriesColor1 = Colors.red; final Color seriesColor2 = Colors.blue; final Color seriesColor3 = Colors.green; return >[ SplineSeries( markerSettings: MarkerSettings( isVisible: true, color: seriesColor1, height: 12, width: 12, ), dataLabelSettings: DataLabelSettings( labelAlignment: ChartDataLabelAlignment.top, isVisible: true, ), dataSource: chartData, color: seriesColor1, name: 'Грудь', xValueMapper: (Circumference value, int index) => value.createdAt, yValueMapper: (Circumference value, int index) => value.chestCircumference, ), SplineSeries( markerSettings: MarkerSettings( isVisible: true, color: seriesColor2, height: 12, width: 12, ), dataLabelSettings: DataLabelSettings( labelAlignment: ChartDataLabelAlignment.top, isVisible: true, ), dataSource: chartData, color: seriesColor2, name: 'Талия', xValueMapper: (Circumference value, int index) => value.createdAt, yValueMapper: (Circumference value, int index) => value.waistCircumference, ), SplineSeries( markerSettings: MarkerSettings( isVisible: true, color: seriesColor3, height: 12, width: 12, ), dataLabelSettings: DataLabelSettings( labelAlignment: ChartDataLabelAlignment.top, isVisible: true, ), dataSource: chartData, color: seriesColor3, name: 'Бёдра', xValueMapper: (Circumference value, int index) => value.createdAt, yValueMapper: (Circumference value, int index) => value.hipCircumference, ), ]; } }