forked from eatvio/eatvio_app
feat(profile): add weight and imt charts, menu add dividers
This commit is contained in:
@@ -101,6 +101,7 @@ class ChartPoint with _$ChartPoint {
|
||||
@JsonKey(name: "id") required int id,
|
||||
@JsonKey(name: "user_id") required int userId,
|
||||
@JsonKey(name: "weight") required int weight,
|
||||
@JsonKey(name: "bmi") required String bmi,
|
||||
@JsonKey(name: "created_at") required DateTime createdAt,
|
||||
@JsonKey(name: "updated_at") required DateTime updatedAt,
|
||||
}) = _ChartPoint;
|
||||
|
||||
@@ -2122,6 +2122,8 @@ mixin _$ChartPoint {
|
||||
int get userId => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "weight")
|
||||
int get weight => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "bmi")
|
||||
String get bmi => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "created_at")
|
||||
DateTime get createdAt => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "updated_at")
|
||||
@@ -2143,6 +2145,7 @@ abstract class $ChartPointCopyWith<$Res> {
|
||||
{@JsonKey(name: "id") int id,
|
||||
@JsonKey(name: "user_id") int userId,
|
||||
@JsonKey(name: "weight") int weight,
|
||||
@JsonKey(name: "bmi") String bmi,
|
||||
@JsonKey(name: "created_at") DateTime createdAt,
|
||||
@JsonKey(name: "updated_at") DateTime updatedAt});
|
||||
}
|
||||
@@ -2163,6 +2166,7 @@ class _$ChartPointCopyWithImpl<$Res, $Val extends ChartPoint>
|
||||
Object? id = null,
|
||||
Object? userId = null,
|
||||
Object? weight = null,
|
||||
Object? bmi = null,
|
||||
Object? createdAt = null,
|
||||
Object? updatedAt = null,
|
||||
}) {
|
||||
@@ -2179,6 +2183,10 @@ class _$ChartPointCopyWithImpl<$Res, $Val extends ChartPoint>
|
||||
? _value.weight
|
||||
: weight // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
bmi: null == bmi
|
||||
? _value.bmi
|
||||
: bmi // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
createdAt: null == createdAt
|
||||
? _value.createdAt
|
||||
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||
@@ -2203,6 +2211,7 @@ abstract class _$$ChartPointImplCopyWith<$Res>
|
||||
{@JsonKey(name: "id") int id,
|
||||
@JsonKey(name: "user_id") int userId,
|
||||
@JsonKey(name: "weight") int weight,
|
||||
@JsonKey(name: "bmi") String bmi,
|
||||
@JsonKey(name: "created_at") DateTime createdAt,
|
||||
@JsonKey(name: "updated_at") DateTime updatedAt});
|
||||
}
|
||||
@@ -2221,6 +2230,7 @@ class __$$ChartPointImplCopyWithImpl<$Res>
|
||||
Object? id = null,
|
||||
Object? userId = null,
|
||||
Object? weight = null,
|
||||
Object? bmi = null,
|
||||
Object? createdAt = null,
|
||||
Object? updatedAt = null,
|
||||
}) {
|
||||
@@ -2237,6 +2247,10 @@ class __$$ChartPointImplCopyWithImpl<$Res>
|
||||
? _value.weight
|
||||
: weight // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
bmi: null == bmi
|
||||
? _value.bmi
|
||||
: bmi // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
createdAt: null == createdAt
|
||||
? _value.createdAt
|
||||
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||
@@ -2256,6 +2270,7 @@ class _$ChartPointImpl implements _ChartPoint {
|
||||
{@JsonKey(name: "id") required this.id,
|
||||
@JsonKey(name: "user_id") required this.userId,
|
||||
@JsonKey(name: "weight") required this.weight,
|
||||
@JsonKey(name: "bmi") required this.bmi,
|
||||
@JsonKey(name: "created_at") required this.createdAt,
|
||||
@JsonKey(name: "updated_at") required this.updatedAt});
|
||||
|
||||
@@ -2272,6 +2287,9 @@ class _$ChartPointImpl implements _ChartPoint {
|
||||
@JsonKey(name: "weight")
|
||||
final int weight;
|
||||
@override
|
||||
@JsonKey(name: "bmi")
|
||||
final String bmi;
|
||||
@override
|
||||
@JsonKey(name: "created_at")
|
||||
final DateTime createdAt;
|
||||
@override
|
||||
@@ -2280,7 +2298,7 @@ class _$ChartPointImpl implements _ChartPoint {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ChartPoint(id: $id, userId: $userId, weight: $weight, createdAt: $createdAt, updatedAt: $updatedAt)';
|
||||
return 'ChartPoint(id: $id, userId: $userId, weight: $weight, bmi: $bmi, createdAt: $createdAt, updatedAt: $updatedAt)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -2291,6 +2309,7 @@ class _$ChartPointImpl implements _ChartPoint {
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.userId, userId) || other.userId == userId) &&
|
||||
(identical(other.weight, weight) || other.weight == weight) &&
|
||||
(identical(other.bmi, bmi) || other.bmi == bmi) &&
|
||||
(identical(other.createdAt, createdAt) ||
|
||||
other.createdAt == createdAt) &&
|
||||
(identical(other.updatedAt, updatedAt) ||
|
||||
@@ -2300,7 +2319,7 @@ class _$ChartPointImpl implements _ChartPoint {
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, id, userId, weight, createdAt, updatedAt);
|
||||
Object.hash(runtimeType, id, userId, weight, bmi, createdAt, updatedAt);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@@ -2321,6 +2340,7 @@ abstract class _ChartPoint implements ChartPoint {
|
||||
{@JsonKey(name: "id") required final int id,
|
||||
@JsonKey(name: "user_id") required final int userId,
|
||||
@JsonKey(name: "weight") required final int weight,
|
||||
@JsonKey(name: "bmi") required final String bmi,
|
||||
@JsonKey(name: "created_at") required final DateTime createdAt,
|
||||
@JsonKey(name: "updated_at") required final DateTime updatedAt}) =
|
||||
_$ChartPointImpl;
|
||||
@@ -2338,6 +2358,9 @@ abstract class _ChartPoint implements ChartPoint {
|
||||
@JsonKey(name: "weight")
|
||||
int get weight;
|
||||
@override
|
||||
@JsonKey(name: "bmi")
|
||||
String get bmi;
|
||||
@override
|
||||
@JsonKey(name: "created_at")
|
||||
DateTime get createdAt;
|
||||
@override
|
||||
|
||||
@@ -169,6 +169,7 @@ _$ChartPointImpl _$$ChartPointImplFromJson(Map<String, dynamic> json) =>
|
||||
id: (json['id'] as num).toInt(),
|
||||
userId: (json['user_id'] as num).toInt(),
|
||||
weight: (json['weight'] as num).toInt(),
|
||||
bmi: json['bmi'] as String,
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
updatedAt: DateTime.parse(json['updated_at'] as String),
|
||||
);
|
||||
@@ -178,6 +179,7 @@ Map<String, dynamic> _$$ChartPointImplToJson(_$ChartPointImpl instance) =>
|
||||
'id': instance.id,
|
||||
'user_id': instance.userId,
|
||||
'weight': instance.weight,
|
||||
'bmi': instance.bmi,
|
||||
'created_at': instance.createdAt.toIso8601String(),
|
||||
'updated_at': instance.updatedAt.toIso8601String(),
|
||||
};
|
||||
|
||||
@@ -4,6 +4,8 @@ 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';
|
||||
|
||||
@@ -18,6 +20,7 @@ class ProfileScreen extends StatefulWidget {
|
||||
|
||||
class _ProfileScreenState extends State<ProfileScreen> {
|
||||
List<Circumference> chartData = [];
|
||||
List<ChartPoint> chartPoints = [];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -32,6 +35,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
builder: (BuildContext context, ProfileState state) {
|
||||
if (state is ProfileStateLoaded) {
|
||||
chartData = state.profile.circumferences;
|
||||
chartPoints = state.profile.chartPoints;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
toolbarHeight: 0,
|
||||
@@ -48,6 +52,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
),
|
||||
),
|
||||
CircumferenceChartWidget(chartData: chartData),
|
||||
WeightChartWidget(chartPoints: chartPoints),
|
||||
ImtChartWidget(chartPoints: chartPoints),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
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';
|
||||
|
||||
class ImtChartWidget extends StatelessWidget {
|
||||
final List<ProfileModel.ChartPoint> chartPoints;
|
||||
|
||||
const ImtChartWidget({
|
||||
super.key,
|
||||
required this.chartPoints,
|
||||
});
|
||||
|
||||
@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,
|
||||
),
|
||||
),
|
||||
primaryYAxis: NumericAxis(
|
||||
labelFormat: '{value} кг',
|
||||
axisLine: AxisLine(
|
||||
width: 1,
|
||||
),
|
||||
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>(
|
||||
markerSettings: MarkerSettings(
|
||||
isVisible: true,
|
||||
color: Colors.blue,
|
||||
height: 12,
|
||||
width: 12,
|
||||
),
|
||||
dataLabelSettings: DataLabelSettings(
|
||||
labelAlignment: ChartDataLabelAlignment.top,
|
||||
isVisible: true,
|
||||
),
|
||||
dataSource: chartPoints,
|
||||
color: Colors.blue,
|
||||
name: 'ИМТ',
|
||||
xValueMapper: (ProfileModel.ChartPoint value, int index) => value.createdAt,
|
||||
yValueMapper: (ProfileModel.ChartPoint value, int index) => double.parse(value.bmi),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
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';
|
||||
|
||||
class WeightChartWidget extends StatelessWidget {
|
||||
final List<ProfileModel.ChartPoint> chartPoints;
|
||||
|
||||
const WeightChartWidget({
|
||||
super.key,
|
||||
required this.chartPoints,
|
||||
});
|
||||
|
||||
@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,
|
||||
),
|
||||
),
|
||||
primaryYAxis: NumericAxis(
|
||||
labelFormat: '{value} кг',
|
||||
axisLine: AxisLine(
|
||||
width: 1,
|
||||
),
|
||||
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>(
|
||||
markerSettings: MarkerSettings(
|
||||
isVisible: true,
|
||||
color: Colors.blue,
|
||||
height: 12,
|
||||
width: 12,
|
||||
),
|
||||
dataLabelSettings: DataLabelSettings(
|
||||
labelAlignment: ChartDataLabelAlignment.top,
|
||||
isVisible: true,
|
||||
),
|
||||
dataSource: chartPoints,
|
||||
color: Colors.blue,
|
||||
name: 'Вес',
|
||||
xValueMapper: (ProfileModel.ChartPoint value, int index) => value.createdAt,
|
||||
yValueMapper: (ProfileModel.ChartPoint value, int index) => value.weight,
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user