feat(profile): add blogPosts of user, charts

This commit is contained in:
mso7nueh
2024-08-30 16:36:22 +03:00
parent f994589baa
commit 01d6fea790
20 changed files with 582 additions and 164 deletions

View File

@@ -13,6 +13,7 @@ class ProfileCubit extends Cubit<ProfileState> {
try {
emit(ProfileState.loaded(
profile: await profileRepository.getProfileBySlug(slug),
blogPosts: await profileRepository.getBlogPostsByAuthorSlug(slug: slug),
));
} catch (e) {
emit(ProfileState.error(errorMessage: e.toString()));
@@ -22,8 +23,10 @@ class ProfileCubit extends Cubit<ProfileState> {
getMyProfile() async {
try {
final myProfile = await profileRepository.getMyProfile();
emit(ProfileState.loaded(
profile: await profileRepository.getMyProfile(),
profile: myProfile,
blogPosts: await profileRepository.getBlogPostsByAuthorSlug(slug: myProfile.user.slug),
));
} catch (e) {
emit(ProfileState.error(errorMessage: e.toString()));

View File

@@ -1,3 +1,4 @@
import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -11,6 +12,7 @@ abstract class ProfileState with _$ProfileState {
const factory ProfileState.loaded({
required ProfileModel profile,
required List<FeedBlogPostModel> blogPosts,
}) = ProfileStateLoaded;
const factory ProfileState.error({

View File

@@ -20,7 +20,9 @@ mixin _$ProfileState {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(ProfileModel profile) loaded,
required TResult Function(
ProfileModel profile, List<FeedBlogPostModel> blogPosts)
loaded,
required TResult Function(String errorMessage) error,
}) =>
throw _privateConstructorUsedError;
@@ -28,7 +30,8 @@ mixin _$ProfileState {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(ProfileModel profile)? loaded,
TResult? Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
loaded,
TResult? Function(String errorMessage)? error,
}) =>
throw _privateConstructorUsedError;
@@ -36,7 +39,8 @@ mixin _$ProfileState {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(ProfileModel profile)? loaded,
TResult Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) =>
@@ -126,7 +130,9 @@ class _$ProfileStateImpl implements _ProfileState {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(ProfileModel profile) loaded,
required TResult Function(
ProfileModel profile, List<FeedBlogPostModel> blogPosts)
loaded,
required TResult Function(String errorMessage) error,
}) {
return $default();
@@ -137,7 +143,8 @@ class _$ProfileStateImpl implements _ProfileState {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(ProfileModel profile)? loaded,
TResult? Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
return $default?.call();
@@ -148,7 +155,8 @@ class _$ProfileStateImpl implements _ProfileState {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(ProfileModel profile)? loaded,
TResult Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
@@ -241,7 +249,9 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(ProfileModel profile) loaded,
required TResult Function(
ProfileModel profile, List<FeedBlogPostModel> blogPosts)
loaded,
required TResult Function(String errorMessage) error,
}) {
return loading();
@@ -252,7 +262,8 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(ProfileModel profile)? loaded,
TResult? Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
return loading?.call();
@@ -263,7 +274,8 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(ProfileModel profile)? loaded,
TResult Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
@@ -321,7 +333,7 @@ abstract class _$$ProfileStateLoadedImplCopyWith<$Res> {
$Res Function(_$ProfileStateLoadedImpl) then) =
__$$ProfileStateLoadedImplCopyWithImpl<$Res>;
@useResult
$Res call({ProfileModel profile});
$Res call({ProfileModel profile, List<FeedBlogPostModel> blogPosts});
$ProfileModelCopyWith<$Res> get profile;
}
@@ -338,12 +350,17 @@ class __$$ProfileStateLoadedImplCopyWithImpl<$Res>
@override
$Res call({
Object? profile = null,
Object? blogPosts = null,
}) {
return _then(_$ProfileStateLoadedImpl(
profile: null == profile
? _value.profile
: profile // ignore: cast_nullable_to_non_nullable
as ProfileModel,
blogPosts: null == blogPosts
? _value._blogPosts
: blogPosts // ignore: cast_nullable_to_non_nullable
as List<FeedBlogPostModel>,
));
}
@@ -359,14 +376,23 @@ class __$$ProfileStateLoadedImplCopyWithImpl<$Res>
/// @nodoc
class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
const _$ProfileStateLoadedImpl({required this.profile});
const _$ProfileStateLoadedImpl(
{required this.profile, required final List<FeedBlogPostModel> blogPosts})
: _blogPosts = blogPosts;
@override
final ProfileModel profile;
final List<FeedBlogPostModel> _blogPosts;
@override
List<FeedBlogPostModel> get blogPosts {
if (_blogPosts is EqualUnmodifiableListView) return _blogPosts;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_blogPosts);
}
@override
String toString() {
return 'ProfileState.loaded(profile: $profile)';
return 'ProfileState.loaded(profile: $profile, blogPosts: $blogPosts)';
}
@override
@@ -374,11 +400,14 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProfileStateLoadedImpl &&
(identical(other.profile, profile) || other.profile == profile));
(identical(other.profile, profile) || other.profile == profile) &&
const DeepCollectionEquality()
.equals(other._blogPosts, _blogPosts));
}
@override
int get hashCode => Object.hash(runtimeType, profile);
int get hashCode => Object.hash(
runtimeType, profile, const DeepCollectionEquality().hash(_blogPosts));
@JsonKey(ignore: true)
@override
@@ -392,10 +421,12 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(ProfileModel profile) loaded,
required TResult Function(
ProfileModel profile, List<FeedBlogPostModel> blogPosts)
loaded,
required TResult Function(String errorMessage) error,
}) {
return loaded(profile);
return loaded(profile, blogPosts);
}
@override
@@ -403,10 +434,11 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(ProfileModel profile)? loaded,
TResult? Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
return loaded?.call(profile);
return loaded?.call(profile, blogPosts);
}
@override
@@ -414,12 +446,13 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(ProfileModel profile)? loaded,
TResult Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(profile);
return loaded(profile, blogPosts);
}
return orElse();
}
@@ -463,10 +496,13 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
}
abstract class ProfileStateLoaded implements ProfileState {
const factory ProfileStateLoaded({required final ProfileModel profile}) =
const factory ProfileStateLoaded(
{required final ProfileModel profile,
required final List<FeedBlogPostModel> blogPosts}) =
_$ProfileStateLoadedImpl;
ProfileModel get profile;
List<FeedBlogPostModel> get blogPosts;
@JsonKey(ignore: true)
_$$ProfileStateLoadedImplCopyWith<_$ProfileStateLoadedImpl> get copyWith =>
throw _privateConstructorUsedError;
@@ -540,7 +576,9 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(ProfileModel profile) loaded,
required TResult Function(
ProfileModel profile, List<FeedBlogPostModel> blogPosts)
loaded,
required TResult Function(String errorMessage) error,
}) {
return error(errorMessage);
@@ -551,7 +589,8 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(ProfileModel profile)? loaded,
TResult? Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
return error?.call(errorMessage);
@@ -562,7 +601,8 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(ProfileModel profile)? loaded,
TResult Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {

View File

@@ -1,5 +1,6 @@
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';
@@ -21,6 +22,10 @@ class ProfileScreen extends StatefulWidget {
class _ProfileScreenState extends State<ProfileScreen> {
List<Circumference> chartData = [];
List<ChartPoint> chartPoints = [];
final List<String> chipsLabelList = ['Вес', 'Замеры', 'ИМТ'];
final List<String> chipsIntervalLabelList = ['1М', '3М', '6М', '1Г', 'ВСЁ ВРЕМЯ'];
int _selectedChipIndex = 0;
int _selectedIntervalChipIndex = 0;
@override
Widget build(BuildContext context) {
@@ -37,23 +42,111 @@ class _ProfileScreenState extends State<ProfileScreen> {
chartData = state.profile.circumferences;
chartPoints = state.profile.chartPoints;
return Scaffold(
appBar: AppBar(
toolbarHeight: 0,
),
backgroundColor: Colors.grey.shade200,
appBar: widget.author == null ? AppBar(toolbarHeight: 0) : AppBar(),
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),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
borderRadius: BorderRadius.vertical(bottom: Radius.circular(16)),
color: Colors.white,
),
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,
),
),
],
),
],
),
),
CircumferenceChartWidget(chartData: chartData),
WeightChartWidget(chartPoints: chartPoints),
ImtChartWidget(chartPoints: chartPoints),
if (widget.author == null) SizedBox(height: 8),
if (widget.author == null)
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: Colors.white,
),
child: 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),
],
),
),
@@ -80,4 +173,55 @@ class _ProfileScreenState extends State<ProfileScreen> {
),
);
}
_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;
});
},
);
}
}

View File

@@ -1,7 +1,7 @@
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:intl/intl.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
class CircumferenceChartWidget extends StatelessWidget {
final List<Circumference> chartData;
@@ -13,35 +13,103 @@ class CircumferenceChartWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return 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,
return Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
Text(
'Грудь ${chartData.last.chestCircumference} см',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.w500,
),
),
chartData.last.chestCircumference > chartData[chartData.length - 2].chestCircumference
? Icon(
Icons.arrow_drop_up,
size: 18,
color: Colors.grey,
)
: Icon(
Icons.arrow_drop_down,
size: 18,
color: Colors.grey,
),
Text(
'Талия ${chartData.last.waistCircumference} см',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.w500,
),
),
chartData.last.waistCircumference > chartData[chartData.length - 2].waistCircumference
? Icon(
Icons.arrow_drop_up,
size: 18,
color: Colors.grey,
)
: Icon(
Icons.arrow_drop_down,
size: 18,
color: Colors.grey,
),
Text(
'Бёдра ${chartData.last.hipCircumference} см',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.w500,
),
),
chartData.last.hipCircumference > chartData[chartData.length - 2].hipCircumference
? Icon(
Icons.arrow_drop_up,
size: 18,
color: Colors.grey,
)
: Icon(
Icons.arrow_drop_down,
size: 18,
color: Colors.grey,
),
],
),
),
),
primaryYAxis: NumericAxis(
labelFormat: '{value} см',
axisLine: AxisLine(
width: 1,
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: DateTimeCategoryAxis(
dateFormat: DateFormat.MMMd('ru'),
axisLine: AxisLine(
width: 1,
),
),
primaryYAxis: NumericAxis(
labelFormat: '{value} см',
axisLine: AxisLine(
width: 1,
),
majorTickLines: MajorTickLines(size: 0),
),
series: _getSplineSeries(),
tooltipBehavior: TooltipBehavior(enable: true),
),
majorTickLines: MajorTickLines(size: 0),
),
series: _getSplineSeries(),
tooltipBehavior: TooltipBehavior(enable: true),
],
);
}

View File

@@ -13,35 +13,61 @@ class ImtChartWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return 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,
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
Text(
'${chartPoints.last.bmi.toStringAsFixed(2)} кг/м²',
style: TextStyle(
color: Colors.black,
fontSize: 48,
fontWeight: FontWeight.w500,
),
),
chartPoints.last.bmi > chartPoints[chartPoints.length - 2].bmi
? Icon(
Icons.arrow_drop_up,
size: 48,
color: Colors.grey,
)
: Icon(
Icons.arrow_drop_down,
size: 48,
color: Colors.grey,
),
],
),
),
),
primaryYAxis: NumericAxis(
labelFormat: '{value} кг',
axisLine: AxisLine(
width: 1,
SfCartesianChart(
margin: EdgeInsets.zero,
enableAxisAnimation: true,
enableSideBySideSeriesPlacement: true,
plotAreaBorderWidth: 0,
trackballBehavior: TrackballBehavior(
enable: true,
activationMode: ActivationMode.singleTap,
),
primaryXAxis: DateTimeCategoryAxis(
dateFormat: DateFormat.MMMd('ru'),
axisLine: AxisLine(
width: 1,
),
),
primaryYAxis: NumericAxis(
labelFormat: '{value} кг/м²',
axisLine: AxisLine(
width: 1,
),
majorTickLines: MajorTickLines(size: 0),
),
series: _getSplineSeries(),
tooltipBehavior: TooltipBehavior(enable: true),
),
majorTickLines: MajorTickLines(size: 0),
),
series: _getSplineSeries(),
tooltipBehavior: TooltipBehavior(enable: true),
],
);
}
@@ -62,7 +88,7 @@ class ImtChartWidget extends StatelessWidget {
color: Colors.blue,
name: 'ИМТ',
xValueMapper: (ProfileModel.ChartPoint value, int index) => value.createdAt,
yValueMapper: (ProfileModel.ChartPoint value, int index) => double.parse(value.bmi),
yValueMapper: (ProfileModel.ChartPoint value, int index) => value.bmi,
),
];
}

View File

@@ -1,7 +1,8 @@
import 'package:eatvio_app/core/app_export.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart' as ProfileModel;
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:intl/intl.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
class WeightChartWidget extends StatelessWidget {
final List<ProfileModel.ChartPoint> chartPoints;
@@ -13,53 +14,103 @@ class WeightChartWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return 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,
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
Text(
'${chartPoints.last.weight} кг',
style: TextStyle(
color: Colors.black,
fontSize: 48,
fontWeight: FontWeight.w500,
),
),
chartPoints.last.weight > chartPoints[chartPoints.length - 2].weight
? Icon(
Icons.arrow_drop_up,
size: 48,
color: Colors.grey.withOpacity(0.4),
)
: Icon(
Icons.arrow_drop_down,
size: 48,
color: Colors.grey.withOpacity(0.4),
),
],
),
),
),
primaryYAxis: NumericAxis(
labelFormat: '{value} кг',
axisLine: AxisLine(
width: 1,
SfCartesianChart(
margin: EdgeInsets.symmetric(horizontal: 8),
enableAxisAnimation: true,
plotAreaBorderWidth: 0,
trackballBehavior: TrackballBehavior(
enable: true,
activationMode: ActivationMode.singleTap,
tooltipDisplayMode: TrackballDisplayMode.groupAllPoints,
tooltipSettings: InteractiveTooltip(),
lineType: TrackballLineType.vertical,
),
primaryXAxis: DateTimeCategoryAxis(
initialVisibleMinimum: chartPoints.first.createdAt,
initialVisibleMaximum: chartPoints.last.createdAt,
tickPosition: TickPosition.inside,
majorTickLines: MajorTickLines(
size: 0,
),
edgeLabelPlacement: EdgeLabelPlacement.shift,
dateFormat: DateFormat.MMMd('ru'),
labelStyle: TextStyle(
color: Colors.grey,
),
majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey.withOpacity(0.3)),
axisLine: AxisLine(
color: Colors.grey.withOpacity(0.3),
width: 0.4,
),
),
primaryYAxis: NumericAxis(
isVisible: false,
labelFormat: '{value} кг',
majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey),
axisLine: AxisLine(
width: 1,
),
majorTickLines: MajorTickLines(size: 0),
),
series: _getSplineSeries(),
tooltipBehavior: TooltipBehavior(enable: true),
),
majorTickLines: MajorTickLines(size: 0),
),
series: _getSplineSeries(),
tooltipBehavior: TooltipBehavior(enable: true),
],
);
}
List<CartesianSeries<ProfileModel.ChartPoint, DateTime>> _getSplineSeries() {
return <CartesianSeries<ProfileModel.ChartPoint, DateTime>>[
SplineSeries<ProfileModel.ChartPoint, DateTime>(
SplineAreaSeries<ProfileModel.ChartPoint, DateTime>(
markerSettings: MarkerSettings(
isVisible: true,
color: Colors.blue,
height: 12,
width: 12,
color: appTheme.blueA400,
height: 8,
width: 8,
),
dataLabelSettings: DataLabelSettings(
labelAlignment: ChartDataLabelAlignment.top,
isVisible: true,
),
dataSource: chartPoints,
color: Colors.blue,
borderColor: appTheme.blueA400,
gradient: LinearGradient(
colors: [
appTheme.blueA400.withOpacity(0.14),
Colors.transparent,
],
begin: Alignment.topCenter,
end: Alignment(0, 0.6),
),
name: 'Вес',
xValueMapper: (ProfileModel.ChartPoint value, int index) => value.createdAt,
yValueMapper: (ProfileModel.ChartPoint value, int index) => value.weight,