diff --git a/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart b/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart index 8628350d..96cbc407 100644 --- a/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart +++ b/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart @@ -103,12 +103,18 @@ class MyProfileBloc extends Bloc { print(data["chartPoints"].runtimeType); print(data["circumferences"]); print(data["circumferences"].runtimeType);*/ - var circumferences = data["circumferences"] ?? - data["circumferences"].asMap().map((index, value) { - return MapEntry(index.toString(), value); - }); + var circumferences = data["circumferences"].isEmpty + ? data["circumferences"].asMap().map((index, value) { + return MapEntry(index.toString(), value); + }) + : data["circumferences"]; + var chartPoints = data["chartPoints"].isEmpty + ? data["chartPoints"].asMap().map((index, value) { + return MapEntry(index.toString(), value); + }) + : data["chartPoints"]; - List weights = [0.0, 0.0, 0.0, 0.0]; + /*List weights = [0.0, 0.0, 0.0, 0.0]; List dates = [ "0000-00-00 00:00:00", "0000-00-00 00:00:00", @@ -119,6 +125,27 @@ class MyProfileBloc extends Bloc { weights[i] = data["chartPoints"][i]["weight"].toDouble(); dates[i] = data["chartPoints"][i]["created_at"].toString(); } + print(data);*/ + List dates = [ + "0000-00-00 00:00:00", + "0000-00-00 00:00:00", + "0000-00-00 00:00:00", + "0000-00-00 00:00:00" + ]; + for (int i = 0; i < data["circumferences"].length; i++) { + dates[i] = data["circumferences"]['$i']["created_at"]; + } + if (chartPoints.length < 4) { + for (int i = chartPoints.length; i < 4; i++) { + chartPoints["$i"] = { + "id": 0, + "user_id": 0, + "weight": 0, + "created_at": "0000-00-00 00:00:00", + "updated_at": "0000-00-00 00:00:00" + }; + } + } if (circumferences.length < 4) { for (int i = circumferences.length; i < 4; i++) { @@ -133,13 +160,16 @@ class MyProfileBloc extends Bloc { }; } } + + /*print(chartPoints); + print(circumferences);*/ /*print(weights); print(weights.runtimeType); print(circumferences); print(circumferences.runtimeType);*/ // Если текущее состояние - начальное, создаем новое загруженное состояние emit(MyProfileLoadedState( - chartPoints: weights, + chartPoints: chartPoints, chartDates: dates, circumferences: circumferences, user: data['user'], diff --git a/lib/presentation/profile/my_profile_screen/bloc/my_profile_state.dart b/lib/presentation/profile/my_profile_screen/bloc/my_profile_state.dart index 13829bb6..5350abe5 100644 --- a/lib/presentation/profile/my_profile_screen/bloc/my_profile_state.dart +++ b/lib/presentation/profile/my_profile_screen/bloc/my_profile_state.dart @@ -59,7 +59,7 @@ class MyProfileLoadedState extends MyProfileState { Map? user; Map? userDetails; Map? circumferences; - List? chartPoints; + Map? chartPoints; List? chartDates; List? plans; TextEditingController? weightController; @@ -130,7 +130,7 @@ class MyProfileLoadedState extends MyProfileState { Map? user, Map? userDetails, List? plans, - List? chartPoints, + Map? chartPoints, List? chartDates, Map? circumferences, TextEditingController? weightController, 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 49db12bd..c3e36a10 100644 --- a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart @@ -59,7 +59,7 @@ class MyProfileScreen extends StatelessWidget { child: Scaffold( appBar: _buildAppBar( context, - ((state.user?['name'] ?? '') + + ((state.userDetails?['first_name'] ?? '') + ' ' + (state.userDetails?['last_name'] ?? '')) ?? 'loading'.tr), @@ -170,9 +170,15 @@ class MyProfileScreen extends StatelessWidget { ), SizedBox(height: 50.v), _buildChart( - context, - state.chartPoints ?? [0.0, 0.0, 0.0, 0.0], - state.chartDates), + context, + state.chartPoints?.values + .map((e) => e['weight']) + .toList() + .map((i) => i.toDouble()) + .toList() ?? + [0.0, 0.0, 0.0, 0.0], + state.chartDates, + ) ])); case 2: // График ИМТ return Column(children: [ @@ -185,7 +191,13 @@ class MyProfileScreen extends StatelessWidget { SizedBox(height: 50.v), _buildChart( context, - _bodyMassIndex(state.chartPoints ?? [0.0, 0.0, 0.0, 0.0], + _bodyMassIndex( + state.chartPoints?.values + .map((e) => e['weight']) + .toList() + .map((i) => i.toDouble()) + .toList() ?? + [0.0, 0.0, 0.0, 0.0], state.userDetails?['height'].toInt() ?? 160), state.chartDates), ]); @@ -740,11 +752,13 @@ class MyProfileScreen extends StatelessWidget { } List _bodyMassIndex(List weightPoints, int height) { + print(weightPoints); List bmiList = []; for (double weight in weightPoints) { double bmi = weight / ((height / 100) * (height / 100)); bmiList.add(bmi); } + print(bmiList); return bmiList; } diff --git a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart index 68e5a00a..2080b034 100644 --- a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart @@ -11,6 +11,7 @@ import 'package:flutter/material.dart'; import 'dart:convert'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:hive/hive.dart'; +import 'package:flutter/services.dart'; import 'package:http/http.dart' as http; class MySettingsScreen extends StatelessWidget { @@ -60,7 +61,7 @@ class MySettingsScreen extends StatelessWidget { NotificationSwitch('Напоминания о заполнении дневника'), SectionTitle('Дополнительная информация'), ExpandableList('Персональные данные'), - ExpandableList('О нас'), + AboutList('О нас', ['ООО Итвио', '2023-н.в.']), ], ), ), @@ -386,11 +387,12 @@ class _ExpandableListState extends State { 'Махачкала', 'Томск', 'Оренбург', - 'Кемерово' + 'Кемерово', ]; List countries = [ 'Россия', ]; + final digitsOnly = FilteringTextInputFormatter.digitsOnly; return Column(children: [ TextField( controller: state.firstNameFormController, @@ -420,7 +422,7 @@ class _ExpandableListState extends State { }), DropdownButtonFormField( value: state.selectedCountry, - hint: Text(state.countryFormController!.text), + hint: Text(state.selectedCountry ?? "Не выбрано"), onChanged: (newValue) { // Обработчик изменения выбранной страны setSelectedCountry(state, newValue); @@ -449,40 +451,40 @@ class _ExpandableListState extends State { decoration: InputDecoration(labelText: 'city_of_living'.tr), ), TextField( - controller: state.weightFormController, - decoration: InputDecoration(labelText: 'weight_measurements'.tr), - keyboardType: TextInputType.number, - ), + controller: state.weightFormController, + decoration: InputDecoration(labelText: 'weight_measurements'.tr), + keyboardType: TextInputType.number, + inputFormatters: [digitsOnly]), TextField( - controller: state.heightFormController, - decoration: InputDecoration(labelText: 'height_measurements'.tr), - keyboardType: TextInputType.number, - ), + controller: state.heightFormController, + decoration: InputDecoration(labelText: 'height_measurements'.tr), + keyboardType: TextInputType.number, + inputFormatters: [digitsOnly]), TextField( - controller: state.chestCircumferenceFormController, - decoration: InputDecoration(labelText: 'chest_circumference'.tr), - keyboardType: TextInputType.number, - ), + controller: state.chestCircumferenceFormController, + decoration: InputDecoration(labelText: 'chest_circumference'.tr), + keyboardType: TextInputType.number, + inputFormatters: [digitsOnly]), TextField( - controller: state.waistCircumferenceFormController, - decoration: InputDecoration(labelText: 'waist_circumference'.tr), - keyboardType: TextInputType.number, - ), + controller: state.waistCircumferenceFormController, + decoration: InputDecoration(labelText: 'waist_circumference'.tr), + keyboardType: TextInputType.number, + inputFormatters: [digitsOnly]), TextField( - controller: state.hipCircumferenceFormController, - decoration: InputDecoration(labelText: 'hip_circumference'.tr), - keyboardType: TextInputType.number, - ), + controller: state.hipCircumferenceFormController, + decoration: InputDecoration(labelText: 'hip_circumference'.tr), + keyboardType: TextInputType.number, + inputFormatters: [digitsOnly]), TextField( - controller: state.upPressureFormController, - decoration: InputDecoration(labelText: 'up_pressure'.tr), - keyboardType: TextInputType.number, - ), + controller: state.upPressureFormController, + decoration: InputDecoration(labelText: 'up_pressure'.tr), + keyboardType: TextInputType.number, + inputFormatters: [digitsOnly]), TextField( - controller: state.downPressureFormController, - decoration: InputDecoration(labelText: 'down_pressure'.tr), - keyboardType: TextInputType.number, - ), + controller: state.downPressureFormController, + decoration: InputDecoration(labelText: 'down_pressure'.tr), + keyboardType: TextInputType.number, + inputFormatters: [digitsOnly]), TextField( controller: state.allergiesFormController, decoration: InputDecoration(labelText: 'allergies_presence'.tr), @@ -572,7 +574,7 @@ class _ExpandableListState extends State { }; final box = await Hive.openBox('token'); final token = box.get('token'); - String apiUrl = dotenv.env['SERVER_ROOT']! + '/profile/edit'; + String apiUrl = dotenv.env['SERVER_ROOT']! + '/profile/update'; http.Response response = await http.post( Uri.parse(apiUrl), body: json.encode(profileData), @@ -612,3 +614,54 @@ class _ExpandableListState extends State { } } } + +class AboutList extends StatefulWidget { + final String title; + final List items; + + AboutList(this.title, this.items); + + @override + _AboutListState createState() => _AboutListState(); +} + +class _AboutListState extends State { + bool isExpanded = false; + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + GestureDetector( + onTap: () { + setState(() { + isExpanded = !isExpanded; + }); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + widget.title, + style: TextStyle( + color: Colors.black, + fontSize: 14, + fontWeight: FontWeight.bold), + ), + Icon(isExpanded ? Icons.arrow_drop_up : Icons.arrow_drop_down), + ], + ), + ), + if (isExpanded) + Padding( + padding: const EdgeInsets.only(left: 16.0), + child: Column( + //children: widget.items.map((item) => Text(item)).toList(), + children: [Text(widget.items.join('\n'))]), + ), + Divider(), + ], + ); + } +}