Weight edit

This commit is contained in:
2024-01-24 13:43:51 +03:00
parent 354174a62b
commit c0fc1beb7c
4 changed files with 117 additions and 120 deletions

View File

@@ -61,6 +61,7 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
chestCircumferenceController: TextEditingController(),
waistCircumferenceController: TextEditingController(),
hipCircumferenceController: TextEditingController(),
weightController: TextEditingController(),
circumferences: data['circumferences'],
));
}

View File

@@ -9,6 +9,7 @@ class MyProfileState extends Equatable {
this.waistCircumferenceController,
this.hipCircumferenceController,
this.myProfileModelObj,
this.weightController,
this.user,
this.userDetails,
this.chartPoints,
@@ -22,6 +23,7 @@ class MyProfileState extends Equatable {
Map<String, dynamic>? chartPoints;
Map<String, dynamic>? circumferences;
List<dynamic>? plans;
TextEditingController? weightController;
TextEditingController? chestCircumferenceController;
TextEditingController? waistCircumferenceController;
TextEditingController? hipCircumferenceController;
@@ -34,6 +36,7 @@ class MyProfileState extends Equatable {
chartPoints,
circumferences,
plans,
weightController,
chestCircumferenceController,
waistCircumferenceController,
hipCircumferenceController,
@@ -46,6 +49,7 @@ class MyProfileState extends Equatable {
List<dynamic>? plans,
Map<String, dynamic>? chartPoints,
Map<String, dynamic>? circumferences,
TextEditingController? weightController,
TextEditingController? chestCircumferenceController,
TextEditingController? waistCircumferenceController,
TextEditingController? hipCircumferenceController,
@@ -58,6 +62,7 @@ class MyProfileState extends Equatable {
userDetails: userDetails ?? this.userDetails,
circumferences: circumferences ?? this.circumferences,
chartPoints: chartPoints ?? this.chartPoints,
weightController: weightController ?? this.weightController,
chestCircumferenceController:
chestCircumferenceController ?? this.chestCircumferenceController,
waistCircumferenceController:

View File

@@ -53,32 +53,37 @@ class MyProfileScreen extends StatelessWidget {
SizedBox(height: 30.v),
CarouselSlider(
options: CarouselOptions(height: 370.0),
items: [1, 2, 3, 4].map((chartType) {
items: [1, 2, 3].map((chartType) {
return Builder(
builder: (BuildContext context) {
switch (chartType) {
case 1: // График веса
return Column(children: [
Text(
"weight_chart".tr,
style: CustomTextStyles.titleMediumBlack
.copyWith(
color: appTheme.black900,
),
),
SizedBox(height: 50.v),
_buildChart(
context,
state.chartPoints?.values
.map<int>((e) => e['weight'])
.toList()
.map((i) => i.toDouble())
.toList() ??
[0.0, 0.0, 0.0, 0.0],
state.chartPoints?.values
.map<String>((e) => e['created_at'])
.toList()),
]);
return GestureDetector(
onTap: () {
_editWeight(context, state);
},
child: Column(children: [
Text(
"weight_chart".tr,
style: CustomTextStyles.titleMediumBlack
.copyWith(
color: appTheme.black900,
),
),
SizedBox(height: 50.v),
_buildChart(
context,
state.chartPoints?.values
.map<int>((e) => e['weight'])
.toList()
.map((i) => i.toDouble())
.toList() ??
[0.0, 0.0, 0.0, 0.0],
state.chartPoints?.values
.map<String>(
(e) => e['created_at'])
.toList()),
]));
case 2: // График ИМТ
return Column(children: [
Text(
@@ -128,7 +133,7 @@ class MyProfileScreen extends StatelessWidget {
.toList()),
_buildChartLegend()
]));
case 4:
/*case 4:
return NextStepButton(
buttonStyle:
CustomButtonStyles.outlinePrimaryTL15,
@@ -136,7 +141,7 @@ class MyProfileScreen extends StatelessWidget {
margin: EdgeInsets.only(left: 10.h),
onPressed: () {
print(dotenv.env['STORAGE_URL']!);
});
});*/
default:
return Text('text',
style: TextStyle(fontSize: 16.0));
@@ -808,8 +813,6 @@ class MyProfileScreen extends StatelessWidget {
String jsonData = json.encode(data);
// Отправка HTTP-запроса
print(jsonData);
print(state.token);
try {
final token = state.token;
final response = await http.post(
@@ -850,4 +853,83 @@ class MyProfileScreen extends StatelessWidget {
},
);
}
_editWeight(BuildContext context, MyProfileState state) {
showDialog(
context: context,
builder: (context) {
final digitsOnly = FilteringTextInputFormatter.digitsOnly;
return AlertDialog(
title: Center(child: Text("add_measure".tr)),
content: SingleChildScrollView(
child: Column(
children: [
Text("weight".tr, style: theme.textTheme.bodyLarge),
SizedBox(height: 5.v),
CustomTextFormField(
controller: state.weightController,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
digitsOnly // Ограничение ввода только цифрами
],
),
],
),
),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text("Отмена", style: theme.textTheme.bodyLarge),
),
TextButton(
onPressed: () async {
Map<String, dynamic> data = {
"weight": state.weightController!.text,
};
// Преобразование Map в JSON
String jsonData = json.encode(data);
// Отправка HTTP-запроса
try {
final token = state.token;
final response = await http.post(
Uri.parse(
dotenv.env['SERVER_ROOT']! + '/profile/addWeight'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
},
body: jsonData,
);
if (response.statusCode == 200) {
Navigator.pushNamed(
context,
AppRoutes.myProfile,
);
} else {
// Ошибка от сервера
print(
"Ошибка при отправке данных. Код ответа: ${response.statusCode}");
}
} catch (e) {
// Обработка ошибок при отправке запроса
print("Ошибка при отправке запроса: $e");
}
},
child: Text("Изменить",
style: CustomTextStyles.titleMediumBlack.copyWith(
color: Colors.blue,
)),
),
],
backgroundColor: Colors.white,
titlePadding: EdgeInsets.all(
20.0), // Можете настроить отступы по вашему желанию
);
},
);
}
}