From 3015e91dd724fb7625cb06ba94c2896a9bece500 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 11 Jan 2024 15:41:06 +0300 Subject: [PATCH] Finished user data retrieve into a state --- .../my_profile_screen/bloc/my_profile_bloc.dart | 9 ++------- .../my_profile_screen/bloc/my_profile_state.dart | 14 ++++++++------ .../my_profile_screen/my_profile_screen.dart | 8 ++++---- 3 files changed, 14 insertions(+), 17 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 bdb02f07..51efc8f8 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 @@ -27,12 +27,7 @@ class MyProfileBloc extends Bloc { 'Authorization': 'Bearer $token', }, ); - - if (response.statusCode == 200) { - final data = jsonDecode(response.body); - print(data); - } else { - // Обработка ошибки - } + final data = jsonDecode(response.body); + emit(state.copyWith(user: data)); } } 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 69dbaaa5..c6fa75ac 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 @@ -4,17 +4,19 @@ part of 'my_profile_bloc.dart'; /// Represents the state of MyProfile in the application. class MyProfileState extends Equatable { - MyProfileState({this.k0ModelObj}); + MyProfileState({this.myProfileModelObj, this.user}); - MyProfileModel? k0ModelObj; + MyProfileModel? myProfileModelObj; + Map? user; @override List get props => [ - k0ModelObj, + myProfileModelObj, ]; - MyProfileState copyWith({MyProfileModel? k0ModelObj}) { + MyProfileState copyWith( + {MyProfileModel? myProfileModelObj, Map? user}) { return MyProfileState( - k0ModelObj: k0ModelObj ?? this.k0ModelObj, - ); + myProfileModelObj: myProfileModelObj ?? this.myProfileModelObj, + user: user ?? this.user); } } 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 00beddde..f2d5b75d 100644 --- a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart @@ -17,7 +17,7 @@ class MyProfileScreen extends StatelessWidget { static Widget builder(BuildContext context) { return BlocProvider( create: (context) => - MyProfileBloc(MyProfileState(k0ModelObj: MyProfileModel())) + MyProfileBloc(MyProfileState(myProfileModelObj: MyProfileModel())) ..add(MyProfileInitialEvent()), child: MyProfileScreen()); } @@ -28,7 +28,7 @@ class MyProfileScreen extends StatelessWidget { builder: (context, state) { return SafeArea( child: Scaffold( - appBar: _buildAppBar(context), + appBar: _buildAppBar(context, state.user!['name']), body: Container( width: double.maxFinite, padding: @@ -56,7 +56,7 @@ class MyProfileScreen extends StatelessWidget { } /// Section Widget - PreferredSizeWidget _buildAppBar(BuildContext context) { + PreferredSizeWidget _buildAppBar(BuildContext context, String username) { return CustomAppBar( height: 54.v, leadingWidth: 28.h, @@ -71,7 +71,7 @@ class MyProfileScreen extends StatelessWidget { child: Row(children: [ AppbarTitleCircleimage(imagePath: ImageConstant.imgEllipse1), AppbarSubtitle( - text: "Dmitry_Koval".tr, + text: username, margin: EdgeInsets.only(left: 35.h, top: 12.v, bottom: 9.v)) ])), actions: [