feat: outlet information page

This commit is contained in:
efrilm
2025-08-19 11:08:33 +07:00
parent de11c1243c
commit 590bb3329c
21 changed files with 2652 additions and 104 deletions
@@ -0,0 +1,40 @@
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/outlet/outlet.dart';
part 'current_outlet_loader_event.dart';
part 'current_outlet_loader_state.dart';
part 'current_outlet_loader_bloc.freezed.dart';
@injectable
class CurrentOutletLoaderBloc
extends Bloc<CurrentOutletLoaderEvent, CurrentOutletLoaderState> {
final IOutletRepository _repository;
CurrentOutletLoaderBloc(this._repository)
: super(CurrentOutletLoaderState.initial()) {
on<CurrentOutletLoaderEvent>(_onCurrentOutletLoaderEvent);
}
Future<void> _onCurrentOutletLoaderEvent(
CurrentOutletLoaderEvent event,
Emitter<CurrentOutletLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(state.copyWith(isFetching: true, failureOptionOutlet: none()));
final result = await _repository.currentOutlet();
var data = result.fold(
(f) => state.copyWith(failureOptionOutlet: optionOf(f)),
(currentOutlet) => state.copyWith(outlet: currentOutlet),
);
emit(data.copyWith(isFetching: false));
},
);
}
}
@@ -0,0 +1,382 @@
// 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 'current_outlet_loader_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 _$CurrentOutletLoaderEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $CurrentOutletLoaderEventCopyWith<$Res> {
factory $CurrentOutletLoaderEventCopyWith(
CurrentOutletLoaderEvent value,
$Res Function(CurrentOutletLoaderEvent) then,
) = _$CurrentOutletLoaderEventCopyWithImpl<$Res, CurrentOutletLoaderEvent>;
}
/// @nodoc
class _$CurrentOutletLoaderEventCopyWithImpl<
$Res,
$Val extends CurrentOutletLoaderEvent
>
implements $CurrentOutletLoaderEventCopyWith<$Res> {
_$CurrentOutletLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of CurrentOutletLoaderEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$CurrentOutletLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of CurrentOutletLoaderEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl();
@override
String toString() {
return 'CurrentOutletLoaderEvent.fetched()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$FetchedImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({required TResult Function() fetched}) {
return fetched();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({TResult? Function()? fetched}) {
return fetched?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements CurrentOutletLoaderEvent {
const factory _Fetched() = _$FetchedImpl;
}
/// @nodoc
mixin _$CurrentOutletLoaderState {
Outlet get outlet => throw _privateConstructorUsedError;
Option<OutletFailure> get failureOptionOutlet =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
/// Create a copy of CurrentOutletLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$CurrentOutletLoaderStateCopyWith<CurrentOutletLoaderState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $CurrentOutletLoaderStateCopyWith<$Res> {
factory $CurrentOutletLoaderStateCopyWith(
CurrentOutletLoaderState value,
$Res Function(CurrentOutletLoaderState) then,
) = _$CurrentOutletLoaderStateCopyWithImpl<$Res, CurrentOutletLoaderState>;
@useResult
$Res call({
Outlet outlet,
Option<OutletFailure> failureOptionOutlet,
bool isFetching,
});
$OutletCopyWith<$Res> get outlet;
}
/// @nodoc
class _$CurrentOutletLoaderStateCopyWithImpl<
$Res,
$Val extends CurrentOutletLoaderState
>
implements $CurrentOutletLoaderStateCopyWith<$Res> {
_$CurrentOutletLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of CurrentOutletLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? outlet = null,
Object? failureOptionOutlet = null,
Object? isFetching = null,
}) {
return _then(
_value.copyWith(
outlet: null == outlet
? _value.outlet
: outlet // ignore: cast_nullable_to_non_nullable
as Outlet,
failureOptionOutlet: null == failureOptionOutlet
? _value.failureOptionOutlet
: failureOptionOutlet // ignore: cast_nullable_to_non_nullable
as Option<OutletFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
/// Create a copy of CurrentOutletLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$OutletCopyWith<$Res> get outlet {
return $OutletCopyWith<$Res>(_value.outlet, (value) {
return _then(_value.copyWith(outlet: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$CurrentOutletLoaderStateImplCopyWith<$Res>
implements $CurrentOutletLoaderStateCopyWith<$Res> {
factory _$$CurrentOutletLoaderStateImplCopyWith(
_$CurrentOutletLoaderStateImpl value,
$Res Function(_$CurrentOutletLoaderStateImpl) then,
) = __$$CurrentOutletLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
Outlet outlet,
Option<OutletFailure> failureOptionOutlet,
bool isFetching,
});
@override
$OutletCopyWith<$Res> get outlet;
}
/// @nodoc
class __$$CurrentOutletLoaderStateImplCopyWithImpl<$Res>
extends
_$CurrentOutletLoaderStateCopyWithImpl<
$Res,
_$CurrentOutletLoaderStateImpl
>
implements _$$CurrentOutletLoaderStateImplCopyWith<$Res> {
__$$CurrentOutletLoaderStateImplCopyWithImpl(
_$CurrentOutletLoaderStateImpl _value,
$Res Function(_$CurrentOutletLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of CurrentOutletLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? outlet = null,
Object? failureOptionOutlet = null,
Object? isFetching = null,
}) {
return _then(
_$CurrentOutletLoaderStateImpl(
outlet: null == outlet
? _value.outlet
: outlet // ignore: cast_nullable_to_non_nullable
as Outlet,
failureOptionOutlet: null == failureOptionOutlet
? _value.failureOptionOutlet
: failureOptionOutlet // ignore: cast_nullable_to_non_nullable
as Option<OutletFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$CurrentOutletLoaderStateImpl implements _CurrentOutletLoaderState {
const _$CurrentOutletLoaderStateImpl({
required this.outlet,
required this.failureOptionOutlet,
this.isFetching = false,
});
@override
final Outlet outlet;
@override
final Option<OutletFailure> failureOptionOutlet;
@override
@JsonKey()
final bool isFetching;
@override
String toString() {
return 'CurrentOutletLoaderState(outlet: $outlet, failureOptionOutlet: $failureOptionOutlet, isFetching: $isFetching)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CurrentOutletLoaderStateImpl &&
(identical(other.outlet, outlet) || other.outlet == outlet) &&
(identical(other.failureOptionOutlet, failureOptionOutlet) ||
other.failureOptionOutlet == failureOptionOutlet) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching));
}
@override
int get hashCode =>
Object.hash(runtimeType, outlet, failureOptionOutlet, isFetching);
/// Create a copy of CurrentOutletLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$CurrentOutletLoaderStateImplCopyWith<_$CurrentOutletLoaderStateImpl>
get copyWith =>
__$$CurrentOutletLoaderStateImplCopyWithImpl<
_$CurrentOutletLoaderStateImpl
>(this, _$identity);
}
abstract class _CurrentOutletLoaderState implements CurrentOutletLoaderState {
const factory _CurrentOutletLoaderState({
required final Outlet outlet,
required final Option<OutletFailure> failureOptionOutlet,
final bool isFetching,
}) = _$CurrentOutletLoaderStateImpl;
@override
Outlet get outlet;
@override
Option<OutletFailure> get failureOptionOutlet;
@override
bool get isFetching;
/// Create a copy of CurrentOutletLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CurrentOutletLoaderStateImplCopyWith<_$CurrentOutletLoaderStateImpl>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,6 @@
part of 'current_outlet_loader_bloc.dart';
@freezed
class CurrentOutletLoaderEvent with _$CurrentOutletLoaderEvent {
const factory CurrentOutletLoaderEvent.fetched() = _Fetched;
}
@@ -0,0 +1,15 @@
part of 'current_outlet_loader_bloc.dart';
@freezed
class CurrentOutletLoaderState with _$CurrentOutletLoaderState {
const factory CurrentOutletLoaderState({
required Outlet outlet,
required Option<OutletFailure> failureOptionOutlet,
@Default(false) bool isFetching,
}) = _CurrentOutletLoaderState;
factory CurrentOutletLoaderState.initial() => CurrentOutletLoaderState(
outlet: Outlet.empty(),
failureOptionOutlet: none(),
);
}