From f469e6f8e88f079643d44c3e0363c8d1c537e5ed Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 16 Jan 2024 10:33:27 +0300 Subject: [PATCH] Added body mass index chart to the carousel --- .../auth/auth_screen/auth_screen.dart | 3 +- .../my_profile_screen/my_profile_screen.dart | 66 ++++++++++++++++++- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/lib/presentation/auth/auth_screen/auth_screen.dart b/lib/presentation/auth/auth_screen/auth_screen.dart index 8e5e76d7..dee1d0ca 100644 --- a/lib/presentation/auth/auth_screen/auth_screen.dart +++ b/lib/presentation/auth/auth_screen/auth_screen.dart @@ -102,8 +102,7 @@ class AuthScreen extends StatelessWidget { context: context, builder: (context) => AlertDialog( title: Text('Ошибка'), - content: - Text(dotenv.env['SERVER_ROOT']! + '/login'), + content: Text('wrong_credentials'.tr), actions: [ TextButton( onPressed: () { diff --git a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart index 88fb2c42..67cb3ad3 100644 --- a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart @@ -7,6 +7,7 @@ import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart'; import 'package:eatvio_app/widgets/custom_bottom_bar.dart'; import 'package:eatvio_app/widgets/app_bar/exit_button.dart'; import 'package:eatvio_app/widgets/next_step_button.dart'; +import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; import 'dart:math'; import 'package:fl_chart/fl_chart.dart'; @@ -39,7 +40,7 @@ class MyProfileScreen extends StatelessWidget { SizedBox(height: 15.v), _buildSettings(context), SizedBox(height: 30.v), - _buildChart( + /*_buildChart( context, state.chartPoints?.values .map((e) => e['weight']) @@ -49,7 +50,59 @@ class MyProfileScreen extends StatelessWidget { [0.0, 0.0, 0.0, 0.0], state.chartPoints?.values .map((e) => e['created_at']) - .toList()), + .toList()),*/ + CarouselSlider( + options: CarouselOptions(height: 370.0), + items: [1, 2, 3].map((chartType) { + return Builder( + builder: (BuildContext context) { + switch (chartType) { + case 1: // График веса + return Container( + decoration: + BoxDecoration(color: Colors.white), + child: _buildChart( + context, + state.chartPoints?.values + .map((e) => e['weight']) + .toList() + .map((i) => i.toDouble()) + .toList() ?? + [0.0, 0.0, 0.0, 0.0], + state.chartPoints?.values + .map((e) => e['created_at']) + .toList()), + ); + case 2: // График ИМТ + return Container( + decoration: + BoxDecoration(color: Colors.white), + child: _buildChart( + context, + _bodyMassIndex( + state.chartPoints!.values + .map((e) => e['weight']) + .toList() + .map((i) => i.toDouble()) + .toList(), + state.userDetails!['height'] + .toInt()) ?? + [0.0, 0.0, 0.0, 0.0], + state.chartPoints?.values + .map((e) => e['created_at']) + .toList()), + ); + case 3: + return Text('text', + style: TextStyle(fontSize: 16.0)); + default: + return Text('text', + style: TextStyle(fontSize: 16.0)); + } + }, + ); + }).toList(), + ), SizedBox(height: 15.v), _buildWidget(context), SizedBox(height: 5.v), @@ -454,4 +507,13 @@ class MyProfileScreen extends StatelessWidget { ])) ])); } + + List _bodyMassIndex(List weightPoints, int height) { + List bmiList = []; + for (double weight in weightPoints) { + double bmi = weight / ((height / 100) * (height / 100)); + bmiList.add(bmi); + } + return bmiList; + } }