feat: update user

This commit is contained in:
efrilm
2025-08-19 15:05:08 +07:00
parent bfd4604897
commit 7919825955
37 changed files with 2531 additions and 897 deletions
@@ -0,0 +1,46 @@
import 'package:dartz/dartz.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/user/user.dart';
part 'user_edit_form_event.dart';
part 'user_edit_form_state.dart';
part 'user_edit_form_bloc.freezed.dart';
@injectable
class UserEditFormBloc extends Bloc<UserEditFormEvent, UserEditFormState> {
final IUserRepository _repository;
UserEditFormBloc(this._repository) : super(UserEditFormState.initial()) {
on<UserEditFormEvent>(_onUserEditFormEvent);
}
Future<void> _onUserEditFormEvent(
UserEditFormEvent event,
Emitter<UserEditFormState> emit,
) {
return event.map(
nameChanged: (e) async {
emit(state.copyWith(name: e.name));
},
submitted: (e) async {
Either<UserFailure, User>? failureOrUser;
emit(state.copyWith(isSubmitting: true, failureOrUserOption: none()));
final nameValid = state.name.isNotEmpty;
if (nameValid) {
failureOrUser = await _repository.editUser(name: state.name);
emit(
state.copyWith(
isSubmitting: false,
failureOrUserOption: optionOf(failureOrUser),
),
);
}
emit(state.copyWith(showErrorMessages: true, isSubmitting: false));
},
);
}
}
@@ -0,0 +1,542 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'user_edit_form_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$UserEditFormEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String name) nameChanged,
required TResult Function() submitted,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String name)? nameChanged,
TResult? Function()? submitted,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String name)? nameChanged,
TResult Function()? submitted,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_NameChanged value) nameChanged,
required TResult Function(_Submitted value) submitted,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_NameChanged value)? nameChanged,
TResult? Function(_Submitted value)? submitted,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_NameChanged value)? nameChanged,
TResult Function(_Submitted value)? submitted,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $UserEditFormEventCopyWith<$Res> {
factory $UserEditFormEventCopyWith(
UserEditFormEvent value,
$Res Function(UserEditFormEvent) then,
) = _$UserEditFormEventCopyWithImpl<$Res, UserEditFormEvent>;
}
/// @nodoc
class _$UserEditFormEventCopyWithImpl<$Res, $Val extends UserEditFormEvent>
implements $UserEditFormEventCopyWith<$Res> {
_$UserEditFormEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of UserEditFormEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$NameChangedImplCopyWith<$Res> {
factory _$$NameChangedImplCopyWith(
_$NameChangedImpl value,
$Res Function(_$NameChangedImpl) then,
) = __$$NameChangedImplCopyWithImpl<$Res>;
@useResult
$Res call({String name});
}
/// @nodoc
class __$$NameChangedImplCopyWithImpl<$Res>
extends _$UserEditFormEventCopyWithImpl<$Res, _$NameChangedImpl>
implements _$$NameChangedImplCopyWith<$Res> {
__$$NameChangedImplCopyWithImpl(
_$NameChangedImpl _value,
$Res Function(_$NameChangedImpl) _then,
) : super(_value, _then);
/// Create a copy of UserEditFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? name = null}) {
return _then(
_$NameChangedImpl(
null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
),
);
}
}
/// @nodoc
class _$NameChangedImpl implements _NameChanged {
const _$NameChangedImpl(this.name);
@override
final String name;
@override
String toString() {
return 'UserEditFormEvent.nameChanged(name: $name)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$NameChangedImpl &&
(identical(other.name, name) || other.name == name));
}
@override
int get hashCode => Object.hash(runtimeType, name);
/// Create a copy of UserEditFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$NameChangedImplCopyWith<_$NameChangedImpl> get copyWith =>
__$$NameChangedImplCopyWithImpl<_$NameChangedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String name) nameChanged,
required TResult Function() submitted,
}) {
return nameChanged(name);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String name)? nameChanged,
TResult? Function()? submitted,
}) {
return nameChanged?.call(name);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String name)? nameChanged,
TResult Function()? submitted,
required TResult orElse(),
}) {
if (nameChanged != null) {
return nameChanged(name);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_NameChanged value) nameChanged,
required TResult Function(_Submitted value) submitted,
}) {
return nameChanged(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_NameChanged value)? nameChanged,
TResult? Function(_Submitted value)? submitted,
}) {
return nameChanged?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_NameChanged value)? nameChanged,
TResult Function(_Submitted value)? submitted,
required TResult orElse(),
}) {
if (nameChanged != null) {
return nameChanged(this);
}
return orElse();
}
}
abstract class _NameChanged implements UserEditFormEvent {
const factory _NameChanged(final String name) = _$NameChangedImpl;
String get name;
/// Create a copy of UserEditFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$NameChangedImplCopyWith<_$NameChangedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$$SubmittedImplCopyWith<$Res> {
factory _$$SubmittedImplCopyWith(
_$SubmittedImpl value,
$Res Function(_$SubmittedImpl) then,
) = __$$SubmittedImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$SubmittedImplCopyWithImpl<$Res>
extends _$UserEditFormEventCopyWithImpl<$Res, _$SubmittedImpl>
implements _$$SubmittedImplCopyWith<$Res> {
__$$SubmittedImplCopyWithImpl(
_$SubmittedImpl _value,
$Res Function(_$SubmittedImpl) _then,
) : super(_value, _then);
/// Create a copy of UserEditFormEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$SubmittedImpl implements _Submitted {
const _$SubmittedImpl();
@override
String toString() {
return 'UserEditFormEvent.submitted()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$SubmittedImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String name) nameChanged,
required TResult Function() submitted,
}) {
return submitted();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String name)? nameChanged,
TResult? Function()? submitted,
}) {
return submitted?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String name)? nameChanged,
TResult Function()? submitted,
required TResult orElse(),
}) {
if (submitted != null) {
return submitted();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_NameChanged value) nameChanged,
required TResult Function(_Submitted value) submitted,
}) {
return submitted(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_NameChanged value)? nameChanged,
TResult? Function(_Submitted value)? submitted,
}) {
return submitted?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_NameChanged value)? nameChanged,
TResult Function(_Submitted value)? submitted,
required TResult orElse(),
}) {
if (submitted != null) {
return submitted(this);
}
return orElse();
}
}
abstract class _Submitted implements UserEditFormEvent {
const factory _Submitted() = _$SubmittedImpl;
}
/// @nodoc
mixin _$UserEditFormState {
String get name => throw _privateConstructorUsedError;
Option<Either<UserFailure, User>> get failureOrUserOption =>
throw _privateConstructorUsedError;
bool get isSubmitting => throw _privateConstructorUsedError;
bool get showErrorMessages => throw _privateConstructorUsedError;
/// Create a copy of UserEditFormState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$UserEditFormStateCopyWith<UserEditFormState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $UserEditFormStateCopyWith<$Res> {
factory $UserEditFormStateCopyWith(
UserEditFormState value,
$Res Function(UserEditFormState) then,
) = _$UserEditFormStateCopyWithImpl<$Res, UserEditFormState>;
@useResult
$Res call({
String name,
Option<Either<UserFailure, User>> failureOrUserOption,
bool isSubmitting,
bool showErrorMessages,
});
}
/// @nodoc
class _$UserEditFormStateCopyWithImpl<$Res, $Val extends UserEditFormState>
implements $UserEditFormStateCopyWith<$Res> {
_$UserEditFormStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of UserEditFormState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? name = null,
Object? failureOrUserOption = null,
Object? isSubmitting = null,
Object? showErrorMessages = null,
}) {
return _then(
_value.copyWith(
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
failureOrUserOption: null == failureOrUserOption
? _value.failureOrUserOption
: failureOrUserOption // ignore: cast_nullable_to_non_nullable
as Option<Either<UserFailure, User>>,
isSubmitting: null == isSubmitting
? _value.isSubmitting
: isSubmitting // ignore: cast_nullable_to_non_nullable
as bool,
showErrorMessages: null == showErrorMessages
? _value.showErrorMessages
: showErrorMessages // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$UserEditFormStateImplCopyWith<$Res>
implements $UserEditFormStateCopyWith<$Res> {
factory _$$UserEditFormStateImplCopyWith(
_$UserEditFormStateImpl value,
$Res Function(_$UserEditFormStateImpl) then,
) = __$$UserEditFormStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
String name,
Option<Either<UserFailure, User>> failureOrUserOption,
bool isSubmitting,
bool showErrorMessages,
});
}
/// @nodoc
class __$$UserEditFormStateImplCopyWithImpl<$Res>
extends _$UserEditFormStateCopyWithImpl<$Res, _$UserEditFormStateImpl>
implements _$$UserEditFormStateImplCopyWith<$Res> {
__$$UserEditFormStateImplCopyWithImpl(
_$UserEditFormStateImpl _value,
$Res Function(_$UserEditFormStateImpl) _then,
) : super(_value, _then);
/// Create a copy of UserEditFormState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? name = null,
Object? failureOrUserOption = null,
Object? isSubmitting = null,
Object? showErrorMessages = null,
}) {
return _then(
_$UserEditFormStateImpl(
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
failureOrUserOption: null == failureOrUserOption
? _value.failureOrUserOption
: failureOrUserOption // ignore: cast_nullable_to_non_nullable
as Option<Either<UserFailure, User>>,
isSubmitting: null == isSubmitting
? _value.isSubmitting
: isSubmitting // ignore: cast_nullable_to_non_nullable
as bool,
showErrorMessages: null == showErrorMessages
? _value.showErrorMessages
: showErrorMessages // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$UserEditFormStateImpl implements _UserEditFormState {
const _$UserEditFormStateImpl({
required this.name,
required this.failureOrUserOption,
this.isSubmitting = false,
this.showErrorMessages = false,
});
@override
final String name;
@override
final Option<Either<UserFailure, User>> failureOrUserOption;
@override
@JsonKey()
final bool isSubmitting;
@override
@JsonKey()
final bool showErrorMessages;
@override
String toString() {
return 'UserEditFormState(name: $name, failureOrUserOption: $failureOrUserOption, isSubmitting: $isSubmitting, showErrorMessages: $showErrorMessages)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$UserEditFormStateImpl &&
(identical(other.name, name) || other.name == name) &&
(identical(other.failureOrUserOption, failureOrUserOption) ||
other.failureOrUserOption == failureOrUserOption) &&
(identical(other.isSubmitting, isSubmitting) ||
other.isSubmitting == isSubmitting) &&
(identical(other.showErrorMessages, showErrorMessages) ||
other.showErrorMessages == showErrorMessages));
}
@override
int get hashCode => Object.hash(
runtimeType,
name,
failureOrUserOption,
isSubmitting,
showErrorMessages,
);
/// Create a copy of UserEditFormState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$UserEditFormStateImplCopyWith<_$UserEditFormStateImpl> get copyWith =>
__$$UserEditFormStateImplCopyWithImpl<_$UserEditFormStateImpl>(
this,
_$identity,
);
}
abstract class _UserEditFormState implements UserEditFormState {
const factory _UserEditFormState({
required final String name,
required final Option<Either<UserFailure, User>> failureOrUserOption,
final bool isSubmitting,
final bool showErrorMessages,
}) = _$UserEditFormStateImpl;
@override
String get name;
@override
Option<Either<UserFailure, User>> get failureOrUserOption;
@override
bool get isSubmitting;
@override
bool get showErrorMessages;
/// Create a copy of UserEditFormState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$UserEditFormStateImplCopyWith<_$UserEditFormStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -0,0 +1,7 @@
part of 'user_edit_form_bloc.dart';
@freezed
class UserEditFormEvent with _$UserEditFormEvent {
const factory UserEditFormEvent.nameChanged(String name) = _NameChanged;
const factory UserEditFormEvent.submitted() = _Submitted;
}
@@ -0,0 +1,14 @@
part of 'user_edit_form_bloc.dart';
@freezed
class UserEditFormState with _$UserEditFormState {
const factory UserEditFormState({
required String name,
required Option<Either<UserFailure, User>> failureOrUserOption,
@Default(false) bool isSubmitting,
@Default(false) bool showErrorMessages,
}) = _UserEditFormState;
factory UserEditFormState.initial() =>
UserEditFormState(name: '', failureOrUserOption: none());
}