From dfb85216b405d57884165a1adf94b145524dd8dd Mon Sep 17 00:00:00 2001 From: maxxkim Date: Sat, 3 Feb 2024 01:45:01 +0300 Subject: [PATCH] [profile]: Finished user profile edit --- .../bloc/my_profile_bloc.dart | 1 - .../my_profile_screen/my_settings_screen.dart | 37 +++++++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart b/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart index ba445a88..215e7d77 100644 --- a/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart +++ b/lib/presentation/profile/my_profile_screen/bloc/my_profile_bloc.dart @@ -114,7 +114,6 @@ class MyProfileBloc extends Bloc { "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(); } diff --git a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart index 98a65436..8955ffb1 100644 --- a/lib/presentation/profile/my_profile_screen/my_settings_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_settings_screen.dart @@ -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 { '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) {