feat: dashboard
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../domain/analytic/analytic.dart';
|
||||
import '../../../domain/analytic/repositories/i_analytic_repository.dart';
|
||||
|
||||
part 'dashboard_analytic_loader_event.dart';
|
||||
part 'dashboard_analytic_loader_state.dart';
|
||||
part 'dashboard_analytic_loader_bloc.freezed.dart';
|
||||
|
||||
@injectable
|
||||
class DashboardAnalyticLoaderBloc
|
||||
extends Bloc<DashboardAnalyticLoaderEvent, DashboardAnalyticLoaderState> {
|
||||
final IAnalyticRepository _repository;
|
||||
DashboardAnalyticLoaderBloc(this._repository)
|
||||
: super(DashboardAnalyticLoaderState.initial()) {
|
||||
on<DashboardAnalyticLoaderEvent>(_onDashboardAnalyticLoaderEvent);
|
||||
}
|
||||
|
||||
Future<void> _onDashboardAnalyticLoaderEvent(
|
||||
DashboardAnalyticLoaderEvent event,
|
||||
Emitter<DashboardAnalyticLoaderState> emit,
|
||||
) {
|
||||
return event.map(
|
||||
fetched: (e) async {
|
||||
emit(
|
||||
state.copyWith(
|
||||
isFetching: true,
|
||||
failureOptionDashboardAnalytic: none(),
|
||||
),
|
||||
);
|
||||
|
||||
final result = await _repository.getDashboard(
|
||||
dateFrom: DateTime.now().subtract(const Duration(days: 30)),
|
||||
dateTo: DateTime.now(),
|
||||
);
|
||||
|
||||
var data = result.fold(
|
||||
(f) => state.copyWith(failureOptionDashboardAnalytic: optionOf(f)),
|
||||
(dashboardAnalytic) =>
|
||||
state.copyWith(dashboardAnalytic: dashboardAnalytic),
|
||||
);
|
||||
|
||||
emit(data.copyWith(isFetching: false));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
+406
@@ -0,0 +1,406 @@
|
||||
// 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 'dashboard_analytic_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 _$DashboardAnalyticLoaderEvent {
|
||||
@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 $DashboardAnalyticLoaderEventCopyWith<$Res> {
|
||||
factory $DashboardAnalyticLoaderEventCopyWith(
|
||||
DashboardAnalyticLoaderEvent value,
|
||||
$Res Function(DashboardAnalyticLoaderEvent) then,
|
||||
) =
|
||||
_$DashboardAnalyticLoaderEventCopyWithImpl<
|
||||
$Res,
|
||||
DashboardAnalyticLoaderEvent
|
||||
>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$DashboardAnalyticLoaderEventCopyWithImpl<
|
||||
$Res,
|
||||
$Val extends DashboardAnalyticLoaderEvent
|
||||
>
|
||||
implements $DashboardAnalyticLoaderEventCopyWith<$Res> {
|
||||
_$DashboardAnalyticLoaderEventCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of DashboardAnalyticLoaderEvent
|
||||
/// 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 _$DashboardAnalyticLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
|
||||
implements _$$FetchedImplCopyWith<$Res> {
|
||||
__$$FetchedImplCopyWithImpl(
|
||||
_$FetchedImpl _value,
|
||||
$Res Function(_$FetchedImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of DashboardAnalyticLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$FetchedImpl implements _Fetched {
|
||||
const _$FetchedImpl();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'DashboardAnalyticLoaderEvent.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 DashboardAnalyticLoaderEvent {
|
||||
const factory _Fetched() = _$FetchedImpl;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$DashboardAnalyticLoaderState {
|
||||
DashboardAnalytic get dashboardAnalytic => throw _privateConstructorUsedError;
|
||||
Option<AnalyticFailure> get failureOptionDashboardAnalytic =>
|
||||
throw _privateConstructorUsedError;
|
||||
bool get isFetching => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of DashboardAnalyticLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$DashboardAnalyticLoaderStateCopyWith<DashboardAnalyticLoaderState>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $DashboardAnalyticLoaderStateCopyWith<$Res> {
|
||||
factory $DashboardAnalyticLoaderStateCopyWith(
|
||||
DashboardAnalyticLoaderState value,
|
||||
$Res Function(DashboardAnalyticLoaderState) then,
|
||||
) =
|
||||
_$DashboardAnalyticLoaderStateCopyWithImpl<
|
||||
$Res,
|
||||
DashboardAnalyticLoaderState
|
||||
>;
|
||||
@useResult
|
||||
$Res call({
|
||||
DashboardAnalytic dashboardAnalytic,
|
||||
Option<AnalyticFailure> failureOptionDashboardAnalytic,
|
||||
bool isFetching,
|
||||
});
|
||||
|
||||
$DashboardAnalyticCopyWith<$Res> get dashboardAnalytic;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$DashboardAnalyticLoaderStateCopyWithImpl<
|
||||
$Res,
|
||||
$Val extends DashboardAnalyticLoaderState
|
||||
>
|
||||
implements $DashboardAnalyticLoaderStateCopyWith<$Res> {
|
||||
_$DashboardAnalyticLoaderStateCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of DashboardAnalyticLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? dashboardAnalytic = null,
|
||||
Object? failureOptionDashboardAnalytic = null,
|
||||
Object? isFetching = null,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
dashboardAnalytic: null == dashboardAnalytic
|
||||
? _value.dashboardAnalytic
|
||||
: dashboardAnalytic // ignore: cast_nullable_to_non_nullable
|
||||
as DashboardAnalytic,
|
||||
failureOptionDashboardAnalytic:
|
||||
null == failureOptionDashboardAnalytic
|
||||
? _value.failureOptionDashboardAnalytic
|
||||
: failureOptionDashboardAnalytic // ignore: cast_nullable_to_non_nullable
|
||||
as Option<AnalyticFailure>,
|
||||
isFetching: null == isFetching
|
||||
? _value.isFetching
|
||||
: isFetching // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
|
||||
/// Create a copy of DashboardAnalyticLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$DashboardAnalyticCopyWith<$Res> get dashboardAnalytic {
|
||||
return $DashboardAnalyticCopyWith<$Res>(_value.dashboardAnalytic, (value) {
|
||||
return _then(_value.copyWith(dashboardAnalytic: value) as $Val);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$DashboardAnalyticLoaderStateImplCopyWith<$Res>
|
||||
implements $DashboardAnalyticLoaderStateCopyWith<$Res> {
|
||||
factory _$$DashboardAnalyticLoaderStateImplCopyWith(
|
||||
_$DashboardAnalyticLoaderStateImpl value,
|
||||
$Res Function(_$DashboardAnalyticLoaderStateImpl) then,
|
||||
) = __$$DashboardAnalyticLoaderStateImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
DashboardAnalytic dashboardAnalytic,
|
||||
Option<AnalyticFailure> failureOptionDashboardAnalytic,
|
||||
bool isFetching,
|
||||
});
|
||||
|
||||
@override
|
||||
$DashboardAnalyticCopyWith<$Res> get dashboardAnalytic;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$DashboardAnalyticLoaderStateImplCopyWithImpl<$Res>
|
||||
extends
|
||||
_$DashboardAnalyticLoaderStateCopyWithImpl<
|
||||
$Res,
|
||||
_$DashboardAnalyticLoaderStateImpl
|
||||
>
|
||||
implements _$$DashboardAnalyticLoaderStateImplCopyWith<$Res> {
|
||||
__$$DashboardAnalyticLoaderStateImplCopyWithImpl(
|
||||
_$DashboardAnalyticLoaderStateImpl _value,
|
||||
$Res Function(_$DashboardAnalyticLoaderStateImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of DashboardAnalyticLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? dashboardAnalytic = null,
|
||||
Object? failureOptionDashboardAnalytic = null,
|
||||
Object? isFetching = null,
|
||||
}) {
|
||||
return _then(
|
||||
_$DashboardAnalyticLoaderStateImpl(
|
||||
dashboardAnalytic: null == dashboardAnalytic
|
||||
? _value.dashboardAnalytic
|
||||
: dashboardAnalytic // ignore: cast_nullable_to_non_nullable
|
||||
as DashboardAnalytic,
|
||||
failureOptionDashboardAnalytic: null == failureOptionDashboardAnalytic
|
||||
? _value.failureOptionDashboardAnalytic
|
||||
: failureOptionDashboardAnalytic // ignore: cast_nullable_to_non_nullable
|
||||
as Option<AnalyticFailure>,
|
||||
isFetching: null == isFetching
|
||||
? _value.isFetching
|
||||
: isFetching // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$DashboardAnalyticLoaderStateImpl
|
||||
implements _DashboardAnalyticLoaderState {
|
||||
const _$DashboardAnalyticLoaderStateImpl({
|
||||
required this.dashboardAnalytic,
|
||||
required this.failureOptionDashboardAnalytic,
|
||||
this.isFetching = false,
|
||||
});
|
||||
|
||||
@override
|
||||
final DashboardAnalytic dashboardAnalytic;
|
||||
@override
|
||||
final Option<AnalyticFailure> failureOptionDashboardAnalytic;
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool isFetching;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'DashboardAnalyticLoaderState(dashboardAnalytic: $dashboardAnalytic, failureOptionDashboardAnalytic: $failureOptionDashboardAnalytic, isFetching: $isFetching)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$DashboardAnalyticLoaderStateImpl &&
|
||||
(identical(other.dashboardAnalytic, dashboardAnalytic) ||
|
||||
other.dashboardAnalytic == dashboardAnalytic) &&
|
||||
(identical(
|
||||
other.failureOptionDashboardAnalytic,
|
||||
failureOptionDashboardAnalytic,
|
||||
) ||
|
||||
other.failureOptionDashboardAnalytic ==
|
||||
failureOptionDashboardAnalytic) &&
|
||||
(identical(other.isFetching, isFetching) ||
|
||||
other.isFetching == isFetching));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
dashboardAnalytic,
|
||||
failureOptionDashboardAnalytic,
|
||||
isFetching,
|
||||
);
|
||||
|
||||
/// Create a copy of DashboardAnalyticLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$DashboardAnalyticLoaderStateImplCopyWith<
|
||||
_$DashboardAnalyticLoaderStateImpl
|
||||
>
|
||||
get copyWith =>
|
||||
__$$DashboardAnalyticLoaderStateImplCopyWithImpl<
|
||||
_$DashboardAnalyticLoaderStateImpl
|
||||
>(this, _$identity);
|
||||
}
|
||||
|
||||
abstract class _DashboardAnalyticLoaderState
|
||||
implements DashboardAnalyticLoaderState {
|
||||
const factory _DashboardAnalyticLoaderState({
|
||||
required final DashboardAnalytic dashboardAnalytic,
|
||||
required final Option<AnalyticFailure> failureOptionDashboardAnalytic,
|
||||
final bool isFetching,
|
||||
}) = _$DashboardAnalyticLoaderStateImpl;
|
||||
|
||||
@override
|
||||
DashboardAnalytic get dashboardAnalytic;
|
||||
@override
|
||||
Option<AnalyticFailure> get failureOptionDashboardAnalytic;
|
||||
@override
|
||||
bool get isFetching;
|
||||
|
||||
/// Create a copy of DashboardAnalyticLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$DashboardAnalyticLoaderStateImplCopyWith<
|
||||
_$DashboardAnalyticLoaderStateImpl
|
||||
>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
part of 'dashboard_analytic_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
class DashboardAnalyticLoaderEvent with _$DashboardAnalyticLoaderEvent {
|
||||
const factory DashboardAnalyticLoaderEvent.fetched() = _Fetched;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
part of 'dashboard_analytic_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
class DashboardAnalyticLoaderState with _$DashboardAnalyticLoaderState {
|
||||
const factory DashboardAnalyticLoaderState({
|
||||
required DashboardAnalytic dashboardAnalytic,
|
||||
required Option<AnalyticFailure> failureOptionDashboardAnalytic,
|
||||
@Default(false) bool isFetching,
|
||||
}) = _DashboardAnalyticLoaderState;
|
||||
|
||||
factory DashboardAnalyticLoaderState.initial() =>
|
||||
DashboardAnalyticLoaderState(
|
||||
dashboardAnalytic: DashboardAnalytic.empty(),
|
||||
failureOptionDashboardAnalytic: none(),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user