<feat>[profile]: Finished user profile edit

This commit is contained in:
2024-02-03 01:45:01 +03:00
parent f52622aa1d
commit dfb85216b4
2 changed files with 29 additions and 9 deletions

View File

@@ -114,7 +114,6 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
"0000-00-00 00:00:00"
];
for (int i = 0; i < data["chartPoints"].length; i++) {
print(data["chartPoints"][i]["weight"]);
weights[i] = data["chartPoints"][i]["weight"].toDouble();
dates[i] = data["chartPoints"][i]["created_at"].toString();
}

View File

@@ -10,6 +10,7 @@ import 'package:eatvio_app/widgets/next_step_button.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:hive/hive.dart';
import 'package:http/http.dart' as http;
class MySettingsScreen extends StatelessWidget {
@@ -569,21 +570,41 @@ class _ExpandableListState extends State<ExpandableList> {
'has_hypo': state?.hypoFormController,
'has_hyper': state?.hyperFormController,
};
print(profileData);
// Отправляем JSON на сервер
String apiUrl = dotenv.env['SERVER_ROOT']! + 'profile/edit';
final box = await Hive.openBox('token');
final token = box.get('token');
String apiUrl = dotenv.env['SERVER_ROOT']! + '/profile/edit';
http.Response response = await http.post(
Uri.parse(apiUrl),
body: json.encode(profileData),
headers: {'Content-Type': 'application/json'},
encoding: utf8,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
},
);
// Проверяем ответ от сервера
print(response.body);
if (response.statusCode == 200) {
// Редирект
// ваш код для редиректа
Navigator.pushNamed(
context,
AppRoutes.myProfile,
);
} else {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Ошибка'),
content: Text('Ошибка при отправке данных профиля'.tr),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('OK'),
),
],
),
);
throw Exception('Ошибка при отправке данных профиля');
}
} catch (error) {