This commit is contained in:
efrilm
2025-11-10 17:23:26 +07:00
parent 0a8f8d93bb
commit b2b2e2b111
12 changed files with 625 additions and 98 deletions
@@ -0,0 +1,38 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/auth/auth.dart';
part 'logout_event.dart';
part 'logout_state.dart';
part 'logout_bloc.freezed.dart';
@injectable
class LogoutBloc extends Bloc<LogoutEvent, LogoutState> {
final IAuthRepository _authRepository;
LogoutBloc(this._authRepository) : super(LogoutState.initial()) {
on<LogoutEvent>(_onLogoutEvent);
}
Future<void> _onLogoutEvent(LogoutEvent event, Emitter<LogoutState> emit) {
return event.map(
logout: (e) async {
Either<AuthFailure, Unit>? failureOrSuccess;
emit(
state.copyWith(isLoggingOut: true, logoutFailureOrSuccess: none()),
);
failureOrSuccess = await _authRepository.logout();
emit(
state.copyWith(
isLoggingOut: false,
logoutFailureOrSuccess: optionOf(failureOrSuccess),
),
);
},
);
}
}
@@ -0,0 +1,332 @@
// 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 'logout_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 _$LogoutEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({required TResult Function() logout}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({TResult? Function()? logout}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? logout,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Logout value) logout,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Logout value)? logout,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Logout value)? logout,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $LogoutEventCopyWith<$Res> {
factory $LogoutEventCopyWith(
LogoutEvent value,
$Res Function(LogoutEvent) then,
) = _$LogoutEventCopyWithImpl<$Res, LogoutEvent>;
}
/// @nodoc
class _$LogoutEventCopyWithImpl<$Res, $Val extends LogoutEvent>
implements $LogoutEventCopyWith<$Res> {
_$LogoutEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of LogoutEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$LogoutImplCopyWith<$Res> {
factory _$$LogoutImplCopyWith(
_$LogoutImpl value,
$Res Function(_$LogoutImpl) then,
) = __$$LogoutImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$LogoutImplCopyWithImpl<$Res>
extends _$LogoutEventCopyWithImpl<$Res, _$LogoutImpl>
implements _$$LogoutImplCopyWith<$Res> {
__$$LogoutImplCopyWithImpl(
_$LogoutImpl _value,
$Res Function(_$LogoutImpl) _then,
) : super(_value, _then);
/// Create a copy of LogoutEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$LogoutImpl implements _Logout {
const _$LogoutImpl();
@override
String toString() {
return 'LogoutEvent.logout()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$LogoutImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({required TResult Function() logout}) {
return logout();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({TResult? Function()? logout}) {
return logout?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? logout,
required TResult orElse(),
}) {
if (logout != null) {
return logout();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Logout value) logout,
}) {
return logout(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Logout value)? logout,
}) {
return logout?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Logout value)? logout,
required TResult orElse(),
}) {
if (logout != null) {
return logout(this);
}
return orElse();
}
}
abstract class _Logout implements LogoutEvent {
const factory _Logout() = _$LogoutImpl;
}
/// @nodoc
mixin _$LogoutState {
Option<Either<AuthFailure, Unit>> get logoutFailureOrSuccess =>
throw _privateConstructorUsedError;
bool get isLoggingOut => throw _privateConstructorUsedError;
/// Create a copy of LogoutState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$LogoutStateCopyWith<LogoutState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $LogoutStateCopyWith<$Res> {
factory $LogoutStateCopyWith(
LogoutState value,
$Res Function(LogoutState) then,
) = _$LogoutStateCopyWithImpl<$Res, LogoutState>;
@useResult
$Res call({
Option<Either<AuthFailure, Unit>> logoutFailureOrSuccess,
bool isLoggingOut,
});
}
/// @nodoc
class _$LogoutStateCopyWithImpl<$Res, $Val extends LogoutState>
implements $LogoutStateCopyWith<$Res> {
_$LogoutStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of LogoutState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? logoutFailureOrSuccess = null,
Object? isLoggingOut = null,
}) {
return _then(
_value.copyWith(
logoutFailureOrSuccess: null == logoutFailureOrSuccess
? _value.logoutFailureOrSuccess
: logoutFailureOrSuccess // ignore: cast_nullable_to_non_nullable
as Option<Either<AuthFailure, Unit>>,
isLoggingOut: null == isLoggingOut
? _value.isLoggingOut
: isLoggingOut // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$LogoutStateImplCopyWith<$Res>
implements $LogoutStateCopyWith<$Res> {
factory _$$LogoutStateImplCopyWith(
_$LogoutStateImpl value,
$Res Function(_$LogoutStateImpl) then,
) = __$$LogoutStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
Option<Either<AuthFailure, Unit>> logoutFailureOrSuccess,
bool isLoggingOut,
});
}
/// @nodoc
class __$$LogoutStateImplCopyWithImpl<$Res>
extends _$LogoutStateCopyWithImpl<$Res, _$LogoutStateImpl>
implements _$$LogoutStateImplCopyWith<$Res> {
__$$LogoutStateImplCopyWithImpl(
_$LogoutStateImpl _value,
$Res Function(_$LogoutStateImpl) _then,
) : super(_value, _then);
/// Create a copy of LogoutState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? logoutFailureOrSuccess = null,
Object? isLoggingOut = null,
}) {
return _then(
_$LogoutStateImpl(
logoutFailureOrSuccess: null == logoutFailureOrSuccess
? _value.logoutFailureOrSuccess
: logoutFailureOrSuccess // ignore: cast_nullable_to_non_nullable
as Option<Either<AuthFailure, Unit>>,
isLoggingOut: null == isLoggingOut
? _value.isLoggingOut
: isLoggingOut // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$LogoutStateImpl implements _LogoutState {
_$LogoutStateImpl({
required this.logoutFailureOrSuccess,
this.isLoggingOut = false,
});
@override
final Option<Either<AuthFailure, Unit>> logoutFailureOrSuccess;
@override
@JsonKey()
final bool isLoggingOut;
@override
String toString() {
return 'LogoutState(logoutFailureOrSuccess: $logoutFailureOrSuccess, isLoggingOut: $isLoggingOut)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LogoutStateImpl &&
(identical(other.logoutFailureOrSuccess, logoutFailureOrSuccess) ||
other.logoutFailureOrSuccess == logoutFailureOrSuccess) &&
(identical(other.isLoggingOut, isLoggingOut) ||
other.isLoggingOut == isLoggingOut));
}
@override
int get hashCode =>
Object.hash(runtimeType, logoutFailureOrSuccess, isLoggingOut);
/// Create a copy of LogoutState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$LogoutStateImplCopyWith<_$LogoutStateImpl> get copyWith =>
__$$LogoutStateImplCopyWithImpl<_$LogoutStateImpl>(this, _$identity);
}
abstract class _LogoutState implements LogoutState {
factory _LogoutState({
required final Option<Either<AuthFailure, Unit>> logoutFailureOrSuccess,
final bool isLoggingOut,
}) = _$LogoutStateImpl;
@override
Option<Either<AuthFailure, Unit>> get logoutFailureOrSuccess;
@override
bool get isLoggingOut;
/// Create a copy of LogoutState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$LogoutStateImplCopyWith<_$LogoutStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -0,0 +1,6 @@
part of 'logout_bloc.dart';
@freezed
class LogoutEvent with _$LogoutEvent {
const factory LogoutEvent.logout() = _Logout;
}
@@ -0,0 +1,11 @@
part of 'logout_bloc.dart';
@freezed
class LogoutState with _$LogoutState {
factory LogoutState({
required Option<Either<AuthFailure, Unit>> logoutFailureOrSuccess,
@Default(false) bool isLoggingOut,
}) = _LogoutState;
factory LogoutState.initial() => LogoutState(logoutFailureOrSuccess: none());
}