forked from eatvio/eatvio_app
<refactor>[profile]: App is now compatible with new API
This commit is contained in:
@@ -103,12 +103,18 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
|
||||
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<double> weights = [0.0, 0.0, 0.0, 0.0];
|
||||
/*List<double> weights = [0.0, 0.0, 0.0, 0.0];
|
||||
List<String> dates = [
|
||||
"0000-00-00 00:00:00",
|
||||
"0000-00-00 00:00:00",
|
||||
@@ -119,6 +125,27 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
|
||||
weights[i] = data["chartPoints"][i]["weight"].toDouble();
|
||||
dates[i] = data["chartPoints"][i]["created_at"].toString();
|
||||
}
|
||||
print(data);*/
|
||||
List<String> 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<MyProfileEvent, MyProfileState> {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/*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'],
|
||||
|
||||
@@ -59,7 +59,7 @@ class MyProfileLoadedState extends MyProfileState {
|
||||
Map<String, dynamic>? user;
|
||||
Map<String, dynamic>? userDetails;
|
||||
Map<dynamic, dynamic>? circumferences;
|
||||
List<double>? chartPoints;
|
||||
Map<dynamic, dynamic>? chartPoints;
|
||||
List<String>? chartDates;
|
||||
List<dynamic>? plans;
|
||||
TextEditingController? weightController;
|
||||
@@ -130,7 +130,7 @@ class MyProfileLoadedState extends MyProfileState {
|
||||
Map<String, dynamic>? user,
|
||||
Map<String, dynamic>? userDetails,
|
||||
List<dynamic>? plans,
|
||||
List<double>? chartPoints,
|
||||
Map<dynamic, dynamic>? chartPoints,
|
||||
List<String>? chartDates,
|
||||
Map<dynamic, dynamic>? circumferences,
|
||||
TextEditingController? weightController,
|
||||
|
||||
@@ -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<int>((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<int>((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<double> _bodyMassIndex(List<double> weightPoints, int height) {
|
||||
print(weightPoints);
|
||||
List<double> bmiList = [];
|
||||
for (double weight in weightPoints) {
|
||||
double bmi = weight / ((height / 100) * (height / 100));
|
||||
bmiList.add(bmi);
|
||||
}
|
||||
print(bmiList);
|
||||
return bmiList;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ExpandableList> {
|
||||
'Махачкала',
|
||||
'Томск',
|
||||
'Оренбург',
|
||||
'Кемерово'
|
||||
'Кемерово',
|
||||
];
|
||||
List<String> countries = [
|
||||
'Россия',
|
||||
];
|
||||
final digitsOnly = FilteringTextInputFormatter.digitsOnly;
|
||||
return Column(children: [
|
||||
TextField(
|
||||
controller: state.firstNameFormController,
|
||||
@@ -420,7 +422,7 @@ class _ExpandableListState extends State<ExpandableList> {
|
||||
}),
|
||||
DropdownButtonFormField<String>(
|
||||
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<ExpandableList> {
|
||||
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: <TextInputFormatter>[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: <TextInputFormatter>[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: <TextInputFormatter>[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: <TextInputFormatter>[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: <TextInputFormatter>[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: <TextInputFormatter>[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: <TextInputFormatter>[digitsOnly]),
|
||||
TextField(
|
||||
controller: state.allergiesFormController,
|
||||
decoration: InputDecoration(labelText: 'allergies_presence'.tr),
|
||||
@@ -572,7 +574,7 @@ class _ExpandableListState extends State<ExpandableList> {
|
||||
};
|
||||
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<ExpandableList> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AboutList extends StatefulWidget {
|
||||
final String title;
|
||||
final List<String> items;
|
||||
|
||||
AboutList(this.title, this.items);
|
||||
|
||||
@override
|
||||
_AboutListState createState() => _AboutListState();
|
||||
}
|
||||
|
||||
class _AboutListState extends State<AboutList> {
|
||||
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(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user