forked from eatvio/eatvio_app
feat: add settings
This commit is contained in:
@@ -1,6 +1,39 @@
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:eatvio_app/features/settings/models/profile_settings_model.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
||||
import 'package:eatvio_app/features/settings/repositories/service_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class SettingsCubit extends Cubit {
|
||||
SettingsCubit() : super(SettingsState());
|
||||
}
|
||||
class SettingsCubit extends Cubit<SettingsState> {
|
||||
final ProfileRepository profileRepository;
|
||||
final SettingsRepository settingsRepository;
|
||||
|
||||
SettingsCubit({
|
||||
required this.profileRepository,
|
||||
required this.settingsRepository,
|
||||
}) : super(SettingsState.loading());
|
||||
|
||||
init() async {
|
||||
try {
|
||||
emit(SettingsState.loaded(
|
||||
profileSettings: await settingsRepository.getProfileSettings(),
|
||||
profileDetails: await profileRepository.getMyProfileDetails(),
|
||||
));
|
||||
} catch (e) {
|
||||
emit(SettingsState.error(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
updateProfileSettings({
|
||||
required ProfileSettingsModel profileSettingsModel
|
||||
}) async {
|
||||
try {
|
||||
await settingsRepository.updateProfileSettings(
|
||||
profileSettingsModel: profileSettingsModel,
|
||||
);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/features/settings/models/profile_settings_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'settings_state.freezed.dart';
|
||||
@@ -5,8 +7,14 @@ part 'settings_state.freezed.dart';
|
||||
@freezed
|
||||
abstract class SettingsState with _$SettingsState {
|
||||
const factory SettingsState() = _SettingsState;
|
||||
|
||||
const factory SettingsState.loading() = SettingsStateLoading;
|
||||
const factory SettingsState.loaded() = SettingsStateLoaded;
|
||||
|
||||
const factory SettingsState.loaded({
|
||||
required ProfileSettingsModel profileSettings,
|
||||
required ProfileDetailsModel profileDetails,
|
||||
}) = SettingsStateLoaded;
|
||||
|
||||
const factory SettingsState.error({
|
||||
required String errorMessage,
|
||||
}) = SettingsStateError;
|
||||
|
||||
@@ -20,7 +20,9 @@ mixin _$SettingsState {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function() loaded,
|
||||
required TResult Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)
|
||||
loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -28,7 +30,9 @@ mixin _$SettingsState {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function()? loaded,
|
||||
TResult? Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)?
|
||||
loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -36,7 +40,9 @@ mixin _$SettingsState {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function()? loaded,
|
||||
TResult Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)?
|
||||
loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
@@ -132,7 +138,9 @@ class _$SettingsStateImpl implements _SettingsState {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function() loaded,
|
||||
required TResult Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)
|
||||
loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return $default();
|
||||
@@ -143,7 +151,9 @@ class _$SettingsStateImpl implements _SettingsState {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function()? loaded,
|
||||
TResult? Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)?
|
||||
loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return $default?.call();
|
||||
@@ -154,7 +164,9 @@ class _$SettingsStateImpl implements _SettingsState {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function()? loaded,
|
||||
TResult Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)?
|
||||
loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -250,7 +262,9 @@ class _$SettingsStateLoadingImpl implements SettingsStateLoading {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function() loaded,
|
||||
required TResult Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)
|
||||
loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return loading();
|
||||
@@ -261,7 +275,9 @@ class _$SettingsStateLoadingImpl implements SettingsStateLoading {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function()? loaded,
|
||||
TResult? Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)?
|
||||
loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return loading?.call();
|
||||
@@ -272,7 +288,9 @@ class _$SettingsStateLoadingImpl implements SettingsStateLoading {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function()? loaded,
|
||||
TResult Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)?
|
||||
loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -329,6 +347,13 @@ abstract class _$$SettingsStateLoadedImplCopyWith<$Res> {
|
||||
factory _$$SettingsStateLoadedImplCopyWith(_$SettingsStateLoadedImpl value,
|
||||
$Res Function(_$SettingsStateLoadedImpl) then) =
|
||||
__$$SettingsStateLoadedImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call(
|
||||
{ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails});
|
||||
|
||||
$ProfileSettingsModelCopyWith<$Res> get profileSettings;
|
||||
$ProfileDetailsModelCopyWith<$Res> get profileDetails;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -341,37 +366,95 @@ class __$$SettingsStateLoadedImplCopyWithImpl<$Res>
|
||||
|
||||
/// Create a copy of SettingsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? profileSettings = null,
|
||||
Object? profileDetails = null,
|
||||
}) {
|
||||
return _then(_$SettingsStateLoadedImpl(
|
||||
profileSettings: null == profileSettings
|
||||
? _value.profileSettings
|
||||
: profileSettings // ignore: cast_nullable_to_non_nullable
|
||||
as ProfileSettingsModel,
|
||||
profileDetails: null == profileDetails
|
||||
? _value.profileDetails
|
||||
: profileDetails // ignore: cast_nullable_to_non_nullable
|
||||
as ProfileDetailsModel,
|
||||
));
|
||||
}
|
||||
|
||||
/// Create a copy of SettingsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$ProfileSettingsModelCopyWith<$Res> get profileSettings {
|
||||
return $ProfileSettingsModelCopyWith<$Res>(_value.profileSettings, (value) {
|
||||
return _then(_value.copyWith(profileSettings: value));
|
||||
});
|
||||
}
|
||||
|
||||
/// Create a copy of SettingsState
|
||||
/// 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 _$SettingsStateLoadedImpl implements SettingsStateLoaded {
|
||||
const _$SettingsStateLoadedImpl();
|
||||
const _$SettingsStateLoadedImpl(
|
||||
{required this.profileSettings, required this.profileDetails});
|
||||
|
||||
@override
|
||||
final ProfileSettingsModel profileSettings;
|
||||
@override
|
||||
final ProfileDetailsModel profileDetails;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SettingsState.loaded()';
|
||||
return 'SettingsState.loaded(profileSettings: $profileSettings, profileDetails: $profileDetails)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$SettingsStateLoadedImpl);
|
||||
other is _$SettingsStateLoadedImpl &&
|
||||
(identical(other.profileSettings, profileSettings) ||
|
||||
other.profileSettings == profileSettings) &&
|
||||
(identical(other.profileDetails, profileDetails) ||
|
||||
other.profileDetails == profileDetails));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
int get hashCode => Object.hash(runtimeType, profileSettings, profileDetails);
|
||||
|
||||
/// Create a copy of SettingsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$SettingsStateLoadedImplCopyWith<_$SettingsStateLoadedImpl> get copyWith =>
|
||||
__$$SettingsStateLoadedImplCopyWithImpl<_$SettingsStateLoadedImpl>(
|
||||
this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function() loaded,
|
||||
required TResult Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)
|
||||
loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return loaded();
|
||||
return loaded(profileSettings, profileDetails);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -379,10 +462,12 @@ class _$SettingsStateLoadedImpl implements SettingsStateLoaded {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function()? loaded,
|
||||
TResult? Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)?
|
||||
loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return loaded?.call();
|
||||
return loaded?.call(profileSettings, profileDetails);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -390,12 +475,14 @@ class _$SettingsStateLoadedImpl implements SettingsStateLoaded {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function()? loaded,
|
||||
TResult Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)?
|
||||
loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (loaded != null) {
|
||||
return loaded();
|
||||
return loaded(profileSettings, profileDetails);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
@@ -439,7 +526,19 @@ class _$SettingsStateLoadedImpl implements SettingsStateLoaded {
|
||||
}
|
||||
|
||||
abstract class SettingsStateLoaded implements SettingsState {
|
||||
const factory SettingsStateLoaded() = _$SettingsStateLoadedImpl;
|
||||
const factory SettingsStateLoaded(
|
||||
{required final ProfileSettingsModel profileSettings,
|
||||
required final ProfileDetailsModel profileDetails}) =
|
||||
_$SettingsStateLoadedImpl;
|
||||
|
||||
ProfileSettingsModel get profileSettings;
|
||||
ProfileDetailsModel get profileDetails;
|
||||
|
||||
/// Create a copy of SettingsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$SettingsStateLoadedImplCopyWith<_$SettingsStateLoadedImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -514,7 +613,9 @@ class _$SettingsStateErrorImpl implements SettingsStateError {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function() loaded,
|
||||
required TResult Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)
|
||||
loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return error(errorMessage);
|
||||
@@ -525,7 +626,9 @@ class _$SettingsStateErrorImpl implements SettingsStateError {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function()? loaded,
|
||||
TResult? Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)?
|
||||
loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return error?.call(errorMessage);
|
||||
@@ -536,7 +639,9 @@ class _$SettingsStateErrorImpl implements SettingsStateError {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function()? loaded,
|
||||
TResult Function(ProfileSettingsModel profileSettings,
|
||||
ProfileDetailsModel profileDetails)?
|
||||
loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
|
||||
Reference in New Issue
Block a user