forked from eatvio/eatvio_app
Send circ to API
This commit is contained in:
@@ -12,9 +12,11 @@ import 'package:carousel_slider/carousel_slider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'dart:math';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'dart:math';
|
||||
import 'dart:convert';
|
||||
|
||||
class MyProfileScreen extends StatelessWidget {
|
||||
static Widget builder(BuildContext context) {
|
||||
@@ -170,10 +172,53 @@ class MyProfileScreen extends StatelessWidget {
|
||||
.textTheme.bodyLarge),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// Отправка данных на API
|
||||
// Закрытие диалогового окна
|
||||
Navigator.pop(context);
|
||||
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);
|
||||
try {
|
||||
final response =
|
||||
await http.post(
|
||||
Uri.parse(dotenv.env[
|
||||
'SERVER_ROOT']! +
|
||||
'/profile/addCircumference'),
|
||||
headers: {
|
||||
'Content-Type':
|
||||
'application/json',
|
||||
},
|
||||
body: jsonData,
|
||||
);
|
||||
|
||||
if (response.statusCode ==
|
||||
200) {
|
||||
// Успешный ответ от сервера
|
||||
print(
|
||||
"Данные успешно отправлены");
|
||||
} else {
|
||||
// Ошибка от сервера
|
||||
print(
|
||||
"Ошибка при отправке данных. Код ответа: ${response.statusCode}");
|
||||
}
|
||||
} catch (e) {
|
||||
// Обработка ошибок при отправке запроса
|
||||
print(
|
||||
"Ошибка при отправке запроса: $e");
|
||||
}
|
||||
//Navigator.pop(context);
|
||||
},
|
||||
child: Text("Изменить",
|
||||
style: CustomTextStyles
|
||||
|
||||
Reference in New Issue
Block a user