refactor: profile model

This commit is contained in:
mso7nueh
2024-09-09 18:18:35 +03:00
parent 3ccf5b6d92
commit 8ea819c5bc
77 changed files with 2735 additions and 2950 deletions

View File

@@ -13,6 +13,7 @@ class ProfileCubit extends Cubit<ProfileState> {
try {
emit(ProfileState.loaded(
profile: await profileRepository.getProfileBySlug(slug),
profileDetails: await profileRepository.getMyProfileDetails(),
blogPosts: await profileRepository.getBlogPostsByAuthorSlug(slug: slug),
));
} catch (e) {
@@ -23,10 +24,11 @@ class ProfileCubit extends Cubit<ProfileState> {
getMyProfile() async {
try {
final myProfile = await profileRepository.getMyProfile();
final profile = await profileRepository.getMyProfile();
emit(ProfileState.loaded(
profile: myProfile,
blogPosts: await profileRepository.getBlogPostsByAuthorSlug(slug: myProfile.user.slug),
profile: profile,
profileDetails: await profileRepository.getMyProfileDetails(),
blogPosts: await profileRepository.getBlogPostsByAuthorSlug(slug: profile.slug),
));
} catch (e) {
emit(ProfileState.error(errorMessage: e.toString()));
@@ -45,12 +47,7 @@ class ProfileCubit extends Cubit<ProfileState> {
waistCircumference: waistCircumference,
hipCircumference: hipCircumference,
);
emit(
ProfileState.loaded(
profile: await profileRepository.getMyProfile(),
blogPosts: (state as ProfileStateLoaded).blogPosts,
),
);
emit((state as ProfileStateLoaded).copyWith());
} catch (e) {
emit(ProfileState.error(errorMessage: e.toString()));
print(e);
@@ -61,15 +58,8 @@ class ProfileCubit extends Cubit<ProfileState> {
required double weight,
}) async {
try {
await profileRepository.addWeight(
weight: weight,
);
emit(
ProfileState.loaded(
profile: await profileRepository.getMyProfile(),
blogPosts: (state as ProfileStateLoaded).blogPosts,
),
);
await profileRepository.addWeight(weight: weight);
emit((state as ProfileStateLoaded).copyWith());
} catch (e) {
emit(ProfileState.error(errorMessage: e.toString()));
print(e);

View File

@@ -12,6 +12,7 @@ abstract class ProfileState with _$ProfileState {
const factory ProfileState.loaded({
required ProfileModel profile,
required ProfileDetailsModel profileDetails,
required List<FeedBlogPostModel> blogPosts,
}) = ProfileStateLoaded;

View File

@@ -21,7 +21,9 @@ mixin _$ProfileState {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(
ProfileModel profile, List<FeedBlogPostModel> blogPosts)
ProfileModel profile,
ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)
loaded,
required TResult Function(String errorMessage) error,
}) =>
@@ -30,7 +32,8 @@ mixin _$ProfileState {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
TResult? Function(ProfileModel profile, ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)?
loaded,
TResult? Function(String errorMessage)? error,
}) =>
@@ -39,7 +42,8 @@ mixin _$ProfileState {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
TResult Function(ProfileModel profile, ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
@@ -88,6 +92,9 @@ class _$ProfileStateCopyWithImpl<$Res, $Val extends ProfileState>
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ProfileState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -104,6 +111,9 @@ class __$$ProfileStateImplCopyWithImpl<$Res>
__$$ProfileStateImplCopyWithImpl(
_$ProfileStateImpl _value, $Res Function(_$ProfileStateImpl) _then)
: super(_value, _then);
/// Create a copy of ProfileState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -131,7 +141,9 @@ class _$ProfileStateImpl implements _ProfileState {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(
ProfileModel profile, List<FeedBlogPostModel> blogPosts)
ProfileModel profile,
ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)
loaded,
required TResult Function(String errorMessage) error,
}) {
@@ -143,7 +155,8 @@ class _$ProfileStateImpl implements _ProfileState {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
TResult? Function(ProfileModel profile, ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
@@ -155,7 +168,8 @@ class _$ProfileStateImpl implements _ProfileState {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
TResult Function(ProfileModel profile, ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
@@ -222,6 +236,9 @@ class __$$ProfileStateLoadingImplCopyWithImpl<$Res>
__$$ProfileStateLoadingImplCopyWithImpl(_$ProfileStateLoadingImpl _value,
$Res Function(_$ProfileStateLoadingImpl) _then)
: super(_value, _then);
/// Create a copy of ProfileState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -250,7 +267,9 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(
ProfileModel profile, List<FeedBlogPostModel> blogPosts)
ProfileModel profile,
ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)
loaded,
required TResult Function(String errorMessage) error,
}) {
@@ -262,7 +281,8 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
TResult? Function(ProfileModel profile, ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
@@ -274,7 +294,8 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
TResult Function(ProfileModel profile, ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
@@ -333,9 +354,13 @@ abstract class _$$ProfileStateLoadedImplCopyWith<$Res> {
$Res Function(_$ProfileStateLoadedImpl) then) =
__$$ProfileStateLoadedImplCopyWithImpl<$Res>;
@useResult
$Res call({ProfileModel profile, List<FeedBlogPostModel> blogPosts});
$Res call(
{ProfileModel profile,
ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts});
$ProfileModelCopyWith<$Res> get profile;
$ProfileDetailsModelCopyWith<$Res> get profileDetails;
}
/// @nodoc
@@ -346,10 +371,13 @@ class __$$ProfileStateLoadedImplCopyWithImpl<$Res>
$Res Function(_$ProfileStateLoadedImpl) _then)
: super(_value, _then);
/// Create a copy of ProfileState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? profile = null,
Object? profileDetails = null,
Object? blogPosts = null,
}) {
return _then(_$ProfileStateLoadedImpl(
@@ -357,6 +385,10 @@ class __$$ProfileStateLoadedImplCopyWithImpl<$Res>
? _value.profile
: profile // ignore: cast_nullable_to_non_nullable
as ProfileModel,
profileDetails: null == profileDetails
? _value.profileDetails
: profileDetails // ignore: cast_nullable_to_non_nullable
as ProfileDetailsModel,
blogPosts: null == blogPosts
? _value._blogPosts
: blogPosts // ignore: cast_nullable_to_non_nullable
@@ -364,6 +396,8 @@ class __$$ProfileStateLoadedImplCopyWithImpl<$Res>
));
}
/// Create a copy of ProfileState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ProfileModelCopyWith<$Res> get profile {
@@ -371,17 +405,31 @@ class __$$ProfileStateLoadedImplCopyWithImpl<$Res>
return _then(_value.copyWith(profile: value));
});
}
/// Create a copy of ProfileState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ProfileDetailsModelCopyWith<$Res> get profileDetails {
return $ProfileDetailsModelCopyWith<$Res>(_value.profileDetails, (value) {
return _then(_value.copyWith(profileDetails: value));
});
}
}
/// @nodoc
class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
const _$ProfileStateLoadedImpl(
{required this.profile, required final List<FeedBlogPostModel> blogPosts})
{required this.profile,
required this.profileDetails,
required final List<FeedBlogPostModel> blogPosts})
: _blogPosts = blogPosts;
@override
final ProfileModel profile;
@override
final ProfileDetailsModel profileDetails;
final List<FeedBlogPostModel> _blogPosts;
@override
List<FeedBlogPostModel> get blogPosts {
@@ -392,7 +440,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
@override
String toString() {
return 'ProfileState.loaded(profile: $profile, blogPosts: $blogPosts)';
return 'ProfileState.loaded(profile: $profile, profileDetails: $profileDetails, blogPosts: $blogPosts)';
}
@override
@@ -401,15 +449,19 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
(other.runtimeType == runtimeType &&
other is _$ProfileStateLoadedImpl &&
(identical(other.profile, profile) || other.profile == profile) &&
(identical(other.profileDetails, profileDetails) ||
other.profileDetails == profileDetails) &&
const DeepCollectionEquality()
.equals(other._blogPosts, _blogPosts));
}
@override
int get hashCode => Object.hash(
runtimeType, profile, const DeepCollectionEquality().hash(_blogPosts));
int get hashCode => Object.hash(runtimeType, profile, profileDetails,
const DeepCollectionEquality().hash(_blogPosts));
@JsonKey(ignore: true)
/// Create a copy of ProfileState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ProfileStateLoadedImplCopyWith<_$ProfileStateLoadedImpl> get copyWith =>
@@ -422,11 +474,13 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(
ProfileModel profile, List<FeedBlogPostModel> blogPosts)
ProfileModel profile,
ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)
loaded,
required TResult Function(String errorMessage) error,
}) {
return loaded(profile, blogPosts);
return loaded(profile, profileDetails, blogPosts);
}
@override
@@ -434,11 +488,12 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
TResult? Function(ProfileModel profile, ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
return loaded?.call(profile, blogPosts);
return loaded?.call(profile, profileDetails, blogPosts);
}
@override
@@ -446,13 +501,14 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
TResult Function(ProfileModel profile, ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(profile, blogPosts);
return loaded(profile, profileDetails, blogPosts);
}
return orElse();
}
@@ -498,12 +554,17 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
abstract class ProfileStateLoaded implements ProfileState {
const factory ProfileStateLoaded(
{required final ProfileModel profile,
required final ProfileDetailsModel profileDetails,
required final List<FeedBlogPostModel> blogPosts}) =
_$ProfileStateLoadedImpl;
ProfileModel get profile;
ProfileDetailsModel get profileDetails;
List<FeedBlogPostModel> get blogPosts;
@JsonKey(ignore: true)
/// Create a copy of ProfileState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ProfileStateLoadedImplCopyWith<_$ProfileStateLoadedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -525,6 +586,8 @@ class __$$ProfileStateErrorImplCopyWithImpl<$Res>
$Res Function(_$ProfileStateErrorImpl) _then)
: super(_value, _then);
/// Create a copy of ProfileState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
@@ -564,7 +627,9 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
@override
int get hashCode => Object.hash(runtimeType, errorMessage);
@JsonKey(ignore: true)
/// Create a copy of ProfileState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ProfileStateErrorImplCopyWith<_$ProfileStateErrorImpl> get copyWith =>
@@ -577,7 +642,9 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(
ProfileModel profile, List<FeedBlogPostModel> blogPosts)
ProfileModel profile,
ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)
loaded,
required TResult Function(String errorMessage) error,
}) {
@@ -589,7 +656,8 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
TResult? Function(ProfileModel profile, ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
@@ -601,7 +669,8 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(ProfileModel profile, List<FeedBlogPostModel> blogPosts)?
TResult Function(ProfileModel profile, ProfileDetailsModel profileDetails,
List<FeedBlogPostModel> blogPosts)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
@@ -655,7 +724,10 @@ abstract class ProfileStateError implements ProfileState {
_$ProfileStateErrorImpl;
String get errorMessage;
@JsonKey(ignore: true)
/// Create a copy of ProfileState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ProfileStateErrorImplCopyWith<_$ProfileStateErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}