Circ edit in a separate function

This commit is contained in:
2024-01-24 10:58:22 +03:00
parent 2a7e5c4472
commit 354174a62b

View File

@@ -1,3 +1,5 @@
import 'dart:ffi';
import 'bloc/my_profile_bloc.dart';
import 'models/my_profile_model.dart';
import 'package:eatvio_app/core/app_export.dart';
@@ -106,138 +108,7 @@ class MyProfileScreen extends StatelessWidget {
case 3: //График обхватов
return GestureDetector(
onTap: () {
showDialog(
context: context,
builder: (context) {
final digitsOnly =
FilteringTextInputFormatter
.digitsOnly;
return AlertDialog(
title: Center(
child: Text("Добавить замер")),
content: SingleChildScrollView(
child: Column(
children: [
Text("chest_circumference".tr,
style: theme
.textTheme.bodyLarge),
SizedBox(height: 5.v),
CustomTextFormField(
controller: state
.chestCircumferenceController,
keyboardType:
TextInputType.number,
inputFormatters: <TextInputFormatter>[
digitsOnly // Ограничение ввода только цифрами
],
),
SizedBox(height: 15.v),
Text("waist_circumference".tr,
style: theme
.textTheme.bodyLarge),
SizedBox(height: 5.v),
CustomTextFormField(
controller: state
.waistCircumferenceController,
keyboardType:
TextInputType.number,
inputFormatters: <TextInputFormatter>[
digitsOnly // Ограничение ввода только цифрами
],
),
SizedBox(height: 15.v),
Text("hip_circumference".tr,
style: theme
.textTheme.bodyLarge),
SizedBox(height: 5.v),
CustomTextFormField(
controller: state
.hipCircumferenceController,
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 = {
"chest_circumference": state
.chestCircumferenceController!
.text,
"waist_circumference": state
.waistCircumferenceController!
.text,
"hip_circumference": state
.hipCircumferenceController!
.text,
};
// Преобразование Map в JSON
String jsonData =
json.encode(data);
// Отправка HTTP-запроса
print(jsonData);
print(state.token);
try {
final token = state.token;
final response =
await http.post(
Uri.parse(dotenv.env[
'SERVER_ROOT']! +
'/profile/addCircumference'),
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), // Можете настроить отступы по вашему желанию
);
},
);
_editCircumference(context, state);
},
child: Column(children: [
Text(
@@ -872,7 +743,111 @@ class MyProfileScreen extends StatelessWidget {
}
return bmiList;
}
}
_sendDataToApi(String chestCircumference, String waistCircumference,
String hipCircumference) {}
_editCircumference(BuildContext context, MyProfileState state) {
showDialog(
context: context,
builder: (context) {
final digitsOnly = FilteringTextInputFormatter.digitsOnly;
return AlertDialog(
title: Center(child: Text("Добавить замер")),
content: SingleChildScrollView(
child: Column(
children: [
Text("chest_circumference".tr,
style: theme.textTheme.bodyLarge),
SizedBox(height: 5.v),
CustomTextFormField(
controller: state.chestCircumferenceController,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
digitsOnly // Ограничение ввода только цифрами
],
),
SizedBox(height: 15.v),
Text("waist_circumference".tr,
style: theme.textTheme.bodyLarge),
SizedBox(height: 5.v),
CustomTextFormField(
controller: state.waistCircumferenceController,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
digitsOnly // Ограничение ввода только цифрами
],
),
SizedBox(height: 15.v),
Text("hip_circumference".tr, style: theme.textTheme.bodyLarge),
SizedBox(height: 5.v),
CustomTextFormField(
controller: state.hipCircumferenceController,
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 = {
"chest_circumference":
state.chestCircumferenceController!.text,
"waist_circumference":
state.waistCircumferenceController!.text,
"hip_circumference": state.hipCircumferenceController!.text,
};
// Преобразование Map в JSON
String jsonData = json.encode(data);
// Отправка HTTP-запроса
print(jsonData);
print(state.token);
try {
final token = state.token;
final response = await http.post(
Uri.parse(dotenv.env['SERVER_ROOT']! +
'/profile/addCircumference'),
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), // Можете настроить отступы по вашему желанию
);
},
);
}
}