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 38062c2c..4a1c0f1f 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 @@ -55,6 +55,7 @@ class MyProfileBloc extends Bloc { emit(state.copyWith( user: data['user'], userDetails: data['userDetails'], + token: token, chartPoints: data['chartPoints'], plans: data['plans'], chestCircumferenceController: TextEditingController(), diff --git a/lib/presentation/profile/my_profile_screen/bloc/my_profile_state.dart b/lib/presentation/profile/my_profile_screen/bloc/my_profile_state.dart index aa1e7624..2b1e3166 100644 --- a/lib/presentation/profile/my_profile_screen/bloc/my_profile_state.dart +++ b/lib/presentation/profile/my_profile_screen/bloc/my_profile_state.dart @@ -13,6 +13,7 @@ class MyProfileState extends Equatable { this.userDetails, this.chartPoints, this.plans, + this.token, this.circumferences}); MyProfileModel? myProfileModelObj; @@ -24,6 +25,7 @@ class MyProfileState extends Equatable { TextEditingController? chestCircumferenceController; TextEditingController? waistCircumferenceController; TextEditingController? hipCircumferenceController; + String? token; @override List get props => [ @@ -34,7 +36,8 @@ class MyProfileState extends Equatable { plans, chestCircumferenceController, waistCircumferenceController, - hipCircumferenceController + hipCircumferenceController, + token ]; MyProfileState copyWith({ MyProfileModel? myProfileModelObj, @@ -46,6 +49,7 @@ class MyProfileState extends Equatable { TextEditingController? chestCircumferenceController, TextEditingController? waistCircumferenceController, TextEditingController? hipCircumferenceController, + String? token, }) { return MyProfileState( myProfileModelObj: myProfileModelObj ?? this.myProfileModelObj, @@ -60,6 +64,7 @@ class MyProfileState extends Equatable { waistCircumferenceController ?? this.waistCircumferenceController, hipCircumferenceController: hipCircumferenceController ?? this.hipCircumferenceController, + token: token ?? this.token, ); } } diff --git a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart index 9bcea698..691a6869 100644 --- a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart @@ -190,7 +190,9 @@ class MyProfileScreen extends StatelessWidget { // Отправка HTTP-запроса print(jsonData); + print(state.token); try { + final token = state.token; final response = await http.post( Uri.parse(dotenv.env[ @@ -199,15 +201,15 @@ class MyProfileScreen extends StatelessWidget { headers: { 'Content-Type': 'application/json', + 'Authorization': + 'Bearer $token', }, body: jsonData, ); if (response.statusCode == 200) { - // Успешный ответ от сервера - print( - "Данные успешно отправлены"); + Navigator.pop(context); } else { // Ошибка от сервера print( @@ -218,7 +220,6 @@ class MyProfileScreen extends StatelessWidget { print( "Ошибка при отправке запроса: $e"); } - //Navigator.pop(context); }, child: Text("Изменить", style: CustomTextStyles