forked from eatvio/eatvio_app
feat(profile): add profile model
This commit is contained in:
@@ -5,11 +5,26 @@ import 'package:eatvio_app/features/profile/repositories/profile_repository.dart
|
||||
class ProfileCubit extends Cubit<ProfileState> {
|
||||
final ProfileRepository profileRepository;
|
||||
|
||||
ProfileCubit({required this.profileRepository}) : super(const ProfileState.loading());
|
||||
ProfileCubit({
|
||||
required this.profileRepository,
|
||||
}) : super(const ProfileState.loading());
|
||||
|
||||
getProfileBySlug(String slug) async {
|
||||
try {
|
||||
emit(ProfileState.loaded(profile: await profileRepository.getProfileBySlug(slug)));
|
||||
emit(ProfileState.loaded(
|
||||
profile: await profileRepository.getProfileBySlug(slug),
|
||||
));
|
||||
} catch (e) {
|
||||
emit(ProfileState.error(errorMessage: e.toString()));
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
getMyProfile() async {
|
||||
try {
|
||||
emit(ProfileState.loaded(
|
||||
profile: await profileRepository.getMyProfile(),
|
||||
));
|
||||
} catch (e) {
|
||||
emit(ProfileState.error(errorMessage: e.toString()));
|
||||
print(e);
|
||||
|
||||
@@ -10,7 +10,7 @@ abstract class ProfileState with _$ProfileState {
|
||||
const factory ProfileState.loading() = ProfileStateLoading;
|
||||
|
||||
const factory ProfileState.loaded({
|
||||
required Profile profile,
|
||||
required ProfileModel profile,
|
||||
}) = ProfileStateLoaded;
|
||||
|
||||
const factory ProfileState.error({
|
||||
|
||||
@@ -20,7 +20,7 @@ mixin _$ProfileState {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Profile profile) loaded,
|
||||
required TResult Function(ProfileModel profile) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -28,7 +28,7 @@ mixin _$ProfileState {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Profile profile)? loaded,
|
||||
TResult? Function(ProfileModel profile)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -36,7 +36,7 @@ mixin _$ProfileState {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Profile profile)? loaded,
|
||||
TResult Function(ProfileModel profile)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
@@ -126,7 +126,7 @@ class _$ProfileStateImpl implements _ProfileState {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Profile profile) loaded,
|
||||
required TResult Function(ProfileModel profile) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return $default();
|
||||
@@ -137,7 +137,7 @@ class _$ProfileStateImpl implements _ProfileState {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Profile profile)? loaded,
|
||||
TResult? Function(ProfileModel profile)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return $default?.call();
|
||||
@@ -148,7 +148,7 @@ class _$ProfileStateImpl implements _ProfileState {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Profile profile)? loaded,
|
||||
TResult Function(ProfileModel profile)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -241,7 +241,7 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Profile profile) loaded,
|
||||
required TResult Function(ProfileModel profile) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return loading();
|
||||
@@ -252,7 +252,7 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Profile profile)? loaded,
|
||||
TResult? Function(ProfileModel profile)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return loading?.call();
|
||||
@@ -263,7 +263,7 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Profile profile)? loaded,
|
||||
TResult Function(ProfileModel profile)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -321,9 +321,9 @@ abstract class _$$ProfileStateLoadedImplCopyWith<$Res> {
|
||||
$Res Function(_$ProfileStateLoadedImpl) then) =
|
||||
__$$ProfileStateLoadedImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({Profile profile});
|
||||
$Res call({ProfileModel profile});
|
||||
|
||||
$ProfileCopyWith<$Res> get profile;
|
||||
$ProfileModelCopyWith<$Res> get profile;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -343,14 +343,14 @@ class __$$ProfileStateLoadedImplCopyWithImpl<$Res>
|
||||
profile: null == profile
|
||||
? _value.profile
|
||||
: profile // ignore: cast_nullable_to_non_nullable
|
||||
as Profile,
|
||||
as ProfileModel,
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$ProfileCopyWith<$Res> get profile {
|
||||
return $ProfileCopyWith<$Res>(_value.profile, (value) {
|
||||
$ProfileModelCopyWith<$Res> get profile {
|
||||
return $ProfileModelCopyWith<$Res>(_value.profile, (value) {
|
||||
return _then(_value.copyWith(profile: value));
|
||||
});
|
||||
}
|
||||
@@ -362,7 +362,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
|
||||
const _$ProfileStateLoadedImpl({required this.profile});
|
||||
|
||||
@override
|
||||
final Profile profile;
|
||||
final ProfileModel profile;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -392,7 +392,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Profile profile) loaded,
|
||||
required TResult Function(ProfileModel profile) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return loaded(profile);
|
||||
@@ -403,7 +403,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Profile profile)? loaded,
|
||||
TResult? Function(ProfileModel profile)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return loaded?.call(profile);
|
||||
@@ -414,7 +414,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Profile profile)? loaded,
|
||||
TResult Function(ProfileModel profile)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -463,10 +463,10 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
|
||||
}
|
||||
|
||||
abstract class ProfileStateLoaded implements ProfileState {
|
||||
const factory ProfileStateLoaded({required final Profile profile}) =
|
||||
const factory ProfileStateLoaded({required final ProfileModel profile}) =
|
||||
_$ProfileStateLoadedImpl;
|
||||
|
||||
Profile get profile;
|
||||
ProfileModel get profile;
|
||||
@JsonKey(ignore: true)
|
||||
_$$ProfileStateLoadedImplCopyWith<_$ProfileStateLoadedImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -540,7 +540,7 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Profile profile) loaded,
|
||||
required TResult Function(ProfileModel profile) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return error(errorMessage);
|
||||
@@ -551,7 +551,7 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Profile profile)? loaded,
|
||||
TResult? Function(ProfileModel profile)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return error?.call(errorMessage);
|
||||
@@ -562,7 +562,7 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Profile profile)? loaded,
|
||||
TResult Function(ProfileModel profile)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
|
||||
Reference in New Issue
Block a user