EnakPoint & EnakCoin wallet, PIN, outlet, order, community, reward
- Wallet EnakPoint & EnakCoin: beranda, riwayat, saldo kedaluwarsa, kode bayar, tukar EnakCoin, transfer - PIN (buat, ganti, lupa), outlet, riwayat order, game spin - Halaman community, webview, coming soon, dan ikon menu beranda baru - Redesign Reward Saya: kartu tiket, filter chip, detail kode + QR - Hapus customer point loader, menu, dan checkout lama - Base URL ke enaklo-pos-api.altru.id Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5954510b93
commit
f5e3075205
@@ -0,0 +1,102 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../domain/wallet/wallet.dart';
|
||||
|
||||
part 'wallet_history_loader_event.dart';
|
||||
part 'wallet_history_loader_state.dart';
|
||||
part 'wallet_history_loader_bloc.freezed.dart';
|
||||
|
||||
@injectable
|
||||
class WalletHistoryLoaderBloc
|
||||
extends Bloc<WalletHistoryLoaderEvent, WalletHistoryLoaderState> {
|
||||
final IWalletRepository _repository;
|
||||
|
||||
static const int _limit = 20;
|
||||
|
||||
WalletHistoryLoaderBloc(this._repository)
|
||||
: super(WalletHistoryLoaderState.initial()) {
|
||||
on<WalletHistoryLoaderEvent>(_onWalletHistoryLoaderEvent);
|
||||
}
|
||||
|
||||
Future<void> _onWalletHistoryLoaderEvent(
|
||||
WalletHistoryLoaderEvent event,
|
||||
Emitter<WalletHistoryLoaderState> emit,
|
||||
) {
|
||||
return event.map(
|
||||
currencyChanged: (e) async {
|
||||
emit(state.copyWith(currency: e.currency));
|
||||
await _fetchFirstPage(emit);
|
||||
},
|
||||
filterChanged: (e) async {
|
||||
emit(state.copyWith(types: e.types, from: e.from, to: e.to));
|
||||
await _fetchFirstPage(emit);
|
||||
},
|
||||
refreshed: (e) => _fetchFirstPage(emit),
|
||||
loadedMore: (e) async {
|
||||
if (state.isFetching || state.isLoadingMore || !state.hasMore) return;
|
||||
|
||||
final query = state.query;
|
||||
emit(state.copyWith(isLoadingMore: true, failureOption: none()));
|
||||
|
||||
final result = await _fetch(state.page + 1);
|
||||
if (state.query != query) return;
|
||||
|
||||
emit(
|
||||
result
|
||||
.fold(
|
||||
(f) => state.copyWith(failureOption: optionOf(f)),
|
||||
(page) => state.copyWith(
|
||||
items: [...state.items, ...page.items],
|
||||
page: page.page,
|
||||
totalPages: page.totalPages,
|
||||
),
|
||||
)
|
||||
.copyWith(isLoadingMore: false),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _fetchFirstPage(Emitter<WalletHistoryLoaderState> emit) async {
|
||||
final query = state.query;
|
||||
emit(
|
||||
state.copyWith(
|
||||
isFetching: true,
|
||||
items: [],
|
||||
page: 0,
|
||||
totalPages: 0,
|
||||
failureOption: none(),
|
||||
),
|
||||
);
|
||||
|
||||
final result = await _fetch(1);
|
||||
// Tab / filter sudah berganti selama request berjalan.
|
||||
if (state.query != query) return;
|
||||
|
||||
emit(
|
||||
result
|
||||
.fold(
|
||||
(f) => state.copyWith(failureOption: optionOf(f)),
|
||||
(page) => state.copyWith(
|
||||
items: page.items,
|
||||
page: page.page,
|
||||
totalPages: page.totalPages,
|
||||
),
|
||||
)
|
||||
.copyWith(isFetching: false),
|
||||
);
|
||||
}
|
||||
|
||||
Future<Either<WalletFailure, WalletTransactionPage>> _fetch(int page) =>
|
||||
_repository.getTransactions(
|
||||
page: page,
|
||||
limit: _limit,
|
||||
currency: state.currency,
|
||||
types: state.types,
|
||||
from: state.from,
|
||||
to: state.to,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,706 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint, type=warning, deprecated_member_use, deprecated_member_use_from_same_package
|
||||
// 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 'wallet_history_loader_bloc.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$WalletHistoryLoaderEvent {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is WalletHistoryLoaderEvent);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletHistoryLoaderEvent()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class $WalletHistoryLoaderEventCopyWith<$Res> {
|
||||
$WalletHistoryLoaderEventCopyWith(WalletHistoryLoaderEvent _, $Res Function(WalletHistoryLoaderEvent) __);
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [WalletHistoryLoaderEvent].
|
||||
extension WalletHistoryLoaderEventPatterns on WalletHistoryLoaderEvent {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeMap<TResult extends Object?>({TResult Function( _CurrencyChanged value)? currencyChanged,TResult Function( _FilterChanged value)? filterChanged,TResult Function( _Refreshed value)? refreshed,TResult Function( _LoadedMore value)? loadedMore,required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _CurrencyChanged() when currencyChanged != null:
|
||||
return currencyChanged(_that);case _FilterChanged() when filterChanged != null:
|
||||
return filterChanged(_that);case _Refreshed() when refreshed != null:
|
||||
return refreshed(_that);case _LoadedMore() when loadedMore != null:
|
||||
return loadedMore(_that);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult map<TResult extends Object?>({required TResult Function( _CurrencyChanged value) currencyChanged,required TResult Function( _FilterChanged value) filterChanged,required TResult Function( _Refreshed value) refreshed,required TResult Function( _LoadedMore value) loadedMore,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _CurrencyChanged():
|
||||
return currencyChanged(_that);case _FilterChanged():
|
||||
return filterChanged(_that);case _Refreshed():
|
||||
return refreshed(_that);case _LoadedMore():
|
||||
return loadedMore(_that);case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>({TResult? Function( _CurrencyChanged value)? currencyChanged,TResult? Function( _FilterChanged value)? filterChanged,TResult? Function( _Refreshed value)? refreshed,TResult? Function( _LoadedMore value)? loadedMore,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _CurrencyChanged() when currencyChanged != null:
|
||||
return currencyChanged(_that);case _FilterChanged() when filterChanged != null:
|
||||
return filterChanged(_that);case _Refreshed() when refreshed != null:
|
||||
return refreshed(_that);case _LoadedMore() when loadedMore != null:
|
||||
return loadedMore(_that);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function( WalletCurrency currency)? currencyChanged,TResult Function( List<WalletTransactionType> types, DateTime? from, DateTime? to)? filterChanged,TResult Function()? refreshed,TResult Function()? loadedMore,required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _CurrencyChanged() when currencyChanged != null:
|
||||
return currencyChanged(_that.currency);case _FilterChanged() when filterChanged != null:
|
||||
return filterChanged(_that.types,_that.from,_that.to);case _Refreshed() when refreshed != null:
|
||||
return refreshed();case _LoadedMore() when loadedMore != null:
|
||||
return loadedMore();case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function( WalletCurrency currency) currencyChanged,required TResult Function( List<WalletTransactionType> types, DateTime? from, DateTime? to) filterChanged,required TResult Function() refreshed,required TResult Function() loadedMore,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _CurrencyChanged():
|
||||
return currencyChanged(_that.currency);case _FilterChanged():
|
||||
return filterChanged(_that.types,_that.from,_that.to);case _Refreshed():
|
||||
return refreshed();case _LoadedMore():
|
||||
return loadedMore();case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult? Function( WalletCurrency currency)? currencyChanged,TResult? Function( List<WalletTransactionType> types, DateTime? from, DateTime? to)? filterChanged,TResult? Function()? refreshed,TResult? Function()? loadedMore,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _CurrencyChanged() when currencyChanged != null:
|
||||
return currencyChanged(_that.currency);case _FilterChanged() when filterChanged != null:
|
||||
return filterChanged(_that.types,_that.from,_that.to);case _Refreshed() when refreshed != null:
|
||||
return refreshed();case _LoadedMore() when loadedMore != null:
|
||||
return loadedMore();case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _CurrencyChanged implements WalletHistoryLoaderEvent {
|
||||
const _CurrencyChanged(this.currency);
|
||||
|
||||
|
||||
final WalletCurrency currency;
|
||||
|
||||
/// Create a copy of WalletHistoryLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$CurrencyChangedCopyWith<_CurrencyChanged> get copyWith => __$CurrencyChangedCopyWithImpl<_CurrencyChanged>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _CurrencyChanged&&(identical(other.currency, currency) || other.currency == currency));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,currency);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletHistoryLoaderEvent.currencyChanged(currency: $currency)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$CurrencyChangedCopyWith<$Res> implements $WalletHistoryLoaderEventCopyWith<$Res> {
|
||||
factory _$CurrencyChangedCopyWith(_CurrencyChanged value, $Res Function(_CurrencyChanged) _then) = __$CurrencyChangedCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
WalletCurrency currency
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$CurrencyChangedCopyWithImpl<$Res>
|
||||
implements _$CurrencyChangedCopyWith<$Res> {
|
||||
__$CurrencyChangedCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _CurrencyChanged _self;
|
||||
final $Res Function(_CurrencyChanged) _then;
|
||||
|
||||
/// Create a copy of WalletHistoryLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? currency = null,}) {
|
||||
return _then(_CurrencyChanged(
|
||||
null == currency ? _self.currency : currency // ignore: cast_nullable_to_non_nullable
|
||||
as WalletCurrency,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _FilterChanged implements WalletHistoryLoaderEvent {
|
||||
const _FilterChanged({required List<WalletTransactionType> types, this.from, this.to}): _types = types;
|
||||
|
||||
|
||||
final List<WalletTransactionType> _types;
|
||||
List<WalletTransactionType> get types {
|
||||
if (_types is EqualUnmodifiableListView) return _types;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_types);
|
||||
}
|
||||
|
||||
final DateTime? from;
|
||||
final DateTime? to;
|
||||
|
||||
/// Create a copy of WalletHistoryLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$FilterChangedCopyWith<_FilterChanged> get copyWith => __$FilterChangedCopyWithImpl<_FilterChanged>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _FilterChanged&&const DeepCollectionEquality().equals(other.types, _types)&&(identical(other.from, from) || other.from == from)&&(identical(other.to, to) || other.to == to));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,const DeepCollectionEquality().hash(_types),from,to);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletHistoryLoaderEvent.filterChanged(types: $types, from: $from, to: $to)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$FilterChangedCopyWith<$Res> implements $WalletHistoryLoaderEventCopyWith<$Res> {
|
||||
factory _$FilterChangedCopyWith(_FilterChanged value, $Res Function(_FilterChanged) _then) = __$FilterChangedCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
List<WalletTransactionType> types, DateTime? from, DateTime? to
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$FilterChangedCopyWithImpl<$Res>
|
||||
implements _$FilterChangedCopyWith<$Res> {
|
||||
__$FilterChangedCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _FilterChanged _self;
|
||||
final $Res Function(_FilterChanged) _then;
|
||||
|
||||
/// Create a copy of WalletHistoryLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? types = null,Object? from = freezed,Object? to = freezed,}) {
|
||||
return _then(_FilterChanged(
|
||||
types: null == types ? _self._types : types // ignore: cast_nullable_to_non_nullable
|
||||
as List<WalletTransactionType>,from: freezed == from ? _self.from : from // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,to: freezed == to ? _self.to : to // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _Refreshed implements WalletHistoryLoaderEvent {
|
||||
const _Refreshed();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Refreshed);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletHistoryLoaderEvent.refreshed()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _LoadedMore implements WalletHistoryLoaderEvent {
|
||||
const _LoadedMore();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _LoadedMore);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletHistoryLoaderEvent.loadedMore()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// @nodoc
|
||||
mixin _$WalletHistoryLoaderState {
|
||||
|
||||
WalletCurrency get currency; List<WalletTransactionType> get types; DateTime? get from; DateTime? get to; List<WalletTransaction> get items; int get page; int get totalPages; Option<WalletFailure> get failureOption; bool get isFetching; bool get isLoadingMore;
|
||||
/// Create a copy of WalletHistoryLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$WalletHistoryLoaderStateCopyWith<WalletHistoryLoaderState> get copyWith => _$WalletHistoryLoaderStateCopyWithImpl<WalletHistoryLoaderState>(this as WalletHistoryLoaderState, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
final _this = this as WalletHistoryLoaderState;
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is WalletHistoryLoaderState&&(identical(other.currency, _this.currency) || other.currency == _this.currency)&&const DeepCollectionEquality().equals(other.types, _this.types)&&(identical(other.from, _this.from) || other.from == _this.from)&&(identical(other.to, _this.to) || other.to == _this.to)&&const DeepCollectionEquality().equals(other.items, _this.items)&&(identical(other.page, _this.page) || other.page == _this.page)&&(identical(other.totalPages, _this.totalPages) || other.totalPages == _this.totalPages)&&(identical(other.failureOption, _this.failureOption) || other.failureOption == _this.failureOption)&&(identical(other.isFetching, _this.isFetching) || other.isFetching == _this.isFetching)&&(identical(other.isLoadingMore, _this.isLoadingMore) || other.isLoadingMore == _this.isLoadingMore));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as WalletHistoryLoaderState;
|
||||
return Object.hash(runtimeType,_this.currency,const DeepCollectionEquality().hash(_this.types),_this.from,_this.to,const DeepCollectionEquality().hash(_this.items),_this.page,_this.totalPages,_this.failureOption,_this.isFetching,_this.isLoadingMore);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as WalletHistoryLoaderState;
|
||||
return 'WalletHistoryLoaderState(currency: ${_this.currency}, types: ${_this.types}, from: ${_this.from}, to: ${_this.to}, items: ${_this.items}, page: ${_this.page}, totalPages: ${_this.totalPages}, failureOption: ${_this.failureOption}, isFetching: ${_this.isFetching}, isLoadingMore: ${_this.isLoadingMore})';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $WalletHistoryLoaderStateCopyWith<$Res> {
|
||||
factory $WalletHistoryLoaderStateCopyWith(WalletHistoryLoaderState value, $Res Function(WalletHistoryLoaderState) _then) = _$WalletHistoryLoaderStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
WalletCurrency currency, List<WalletTransactionType> types, DateTime? from, DateTime? to, List<WalletTransaction> items, int page, int totalPages, Option<WalletFailure> failureOption, bool isFetching, bool isLoadingMore
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$WalletHistoryLoaderStateCopyWithImpl<$Res>
|
||||
implements $WalletHistoryLoaderStateCopyWith<$Res> {
|
||||
_$WalletHistoryLoaderStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final WalletHistoryLoaderState _self;
|
||||
final $Res Function(WalletHistoryLoaderState) _then;
|
||||
|
||||
/// Create a copy of WalletHistoryLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? currency = null,Object? types = null,Object? from = freezed,Object? to = freezed,Object? items = null,Object? page = null,Object? totalPages = null,Object? failureOption = null,Object? isFetching = null,Object? isLoadingMore = null,}) {
|
||||
return _then(WalletHistoryLoaderState(
|
||||
currency: null == currency ? _self.currency : currency // ignore: cast_nullable_to_non_nullable
|
||||
as WalletCurrency,types: null == types ? _self.types : types // ignore: cast_nullable_to_non_nullable
|
||||
as List<WalletTransactionType>,from: freezed == from ? _self.from : from // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,to: freezed == to ? _self.to : to // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,items: null == items ? _self.items : items // ignore: cast_nullable_to_non_nullable
|
||||
as List<WalletTransaction>,page: null == page ? _self.page : page // ignore: cast_nullable_to_non_nullable
|
||||
as int,totalPages: null == totalPages ? _self.totalPages : totalPages // ignore: cast_nullable_to_non_nullable
|
||||
as int,failureOption: null == failureOption ? _self.failureOption : failureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,isFetching: null == isFetching ? _self.isFetching : isFetching // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isLoadingMore: null == isLoadingMore ? _self.isLoadingMore : isLoadingMore // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [WalletHistoryLoaderState].
|
||||
extension WalletHistoryLoaderStatePatterns on WalletHistoryLoaderState {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _WalletHistoryLoaderState value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletHistoryLoaderState() when $default != null:
|
||||
return $default(_that);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _WalletHistoryLoaderState value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletHistoryLoaderState():
|
||||
return $default(_that);case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _WalletHistoryLoaderState value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletHistoryLoaderState() when $default != null:
|
||||
return $default(_that);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( WalletCurrency currency, List<WalletTransactionType> types, DateTime? from, DateTime? to, List<WalletTransaction> items, int page, int totalPages, Option<WalletFailure> failureOption, bool isFetching, bool isLoadingMore)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletHistoryLoaderState() when $default != null:
|
||||
return $default(_that.currency,_that.types,_that.from,_that.to,_that.items,_that.page,_that.totalPages,_that.failureOption,_that.isFetching,_that.isLoadingMore);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( WalletCurrency currency, List<WalletTransactionType> types, DateTime? from, DateTime? to, List<WalletTransaction> items, int page, int totalPages, Option<WalletFailure> failureOption, bool isFetching, bool isLoadingMore) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletHistoryLoaderState():
|
||||
return $default(_that.currency,_that.types,_that.from,_that.to,_that.items,_that.page,_that.totalPages,_that.failureOption,_that.isFetching,_that.isLoadingMore);case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( WalletCurrency currency, List<WalletTransactionType> types, DateTime? from, DateTime? to, List<WalletTransaction> items, int page, int totalPages, Option<WalletFailure> failureOption, bool isFetching, bool isLoadingMore)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletHistoryLoaderState() when $default != null:
|
||||
return $default(_that.currency,_that.types,_that.from,_that.to,_that.items,_that.page,_that.totalPages,_that.failureOption,_that.isFetching,_that.isLoadingMore);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _WalletHistoryLoaderState extends WalletHistoryLoaderState {
|
||||
const _WalletHistoryLoaderState({required this.currency, required List<WalletTransactionType> types, this.from, this.to, required List<WalletTransaction> items, required this.page, required this.totalPages, required this.failureOption, this.isFetching = false, this.isLoadingMore = false}): _types = types,_items = items,super._();
|
||||
|
||||
|
||||
@override final WalletCurrency currency;
|
||||
final List<WalletTransactionType> _types;
|
||||
@override List<WalletTransactionType> get types {
|
||||
if (_types is EqualUnmodifiableListView) return _types;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_types);
|
||||
}
|
||||
|
||||
@override final DateTime? from;
|
||||
@override final DateTime? to;
|
||||
final List<WalletTransaction> _items;
|
||||
@override List<WalletTransaction> get items {
|
||||
if (_items is EqualUnmodifiableListView) return _items;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_items);
|
||||
}
|
||||
|
||||
@override final int page;
|
||||
@override final int totalPages;
|
||||
@override final Option<WalletFailure> failureOption;
|
||||
@override@JsonKey() final bool isFetching;
|
||||
@override@JsonKey() final bool isLoadingMore;
|
||||
|
||||
/// Create a copy of WalletHistoryLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$WalletHistoryLoaderStateCopyWith<_WalletHistoryLoaderState> get copyWith => __$WalletHistoryLoaderStateCopyWithImpl<_WalletHistoryLoaderState>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _WalletHistoryLoaderState&&(identical(other.currency, currency) || other.currency == currency)&&const DeepCollectionEquality().equals(other.types, _types)&&(identical(other.from, from) || other.from == from)&&(identical(other.to, to) || other.to == to)&&const DeepCollectionEquality().equals(other.items, _items)&&(identical(other.page, page) || other.page == page)&&(identical(other.totalPages, totalPages) || other.totalPages == totalPages)&&(identical(other.failureOption, failureOption) || other.failureOption == failureOption)&&(identical(other.isFetching, isFetching) || other.isFetching == isFetching)&&(identical(other.isLoadingMore, isLoadingMore) || other.isLoadingMore == isLoadingMore));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,currency,const DeepCollectionEquality().hash(_types),from,to,const DeepCollectionEquality().hash(_items),page,totalPages,failureOption,isFetching,isLoadingMore);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletHistoryLoaderState(currency: $currency, types: $types, from: $from, to: $to, items: $items, page: $page, totalPages: $totalPages, failureOption: $failureOption, isFetching: $isFetching, isLoadingMore: $isLoadingMore)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$WalletHistoryLoaderStateCopyWith<$Res> implements $WalletHistoryLoaderStateCopyWith<$Res> {
|
||||
factory _$WalletHistoryLoaderStateCopyWith(_WalletHistoryLoaderState value, $Res Function(_WalletHistoryLoaderState) _then) = __$WalletHistoryLoaderStateCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
WalletCurrency currency, List<WalletTransactionType> types, DateTime? from, DateTime? to, List<WalletTransaction> items, int page, int totalPages, Option<WalletFailure> failureOption, bool isFetching, bool isLoadingMore
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$WalletHistoryLoaderStateCopyWithImpl<$Res>
|
||||
implements _$WalletHistoryLoaderStateCopyWith<$Res> {
|
||||
__$WalletHistoryLoaderStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _WalletHistoryLoaderState _self;
|
||||
final $Res Function(_WalletHistoryLoaderState) _then;
|
||||
|
||||
/// Create a copy of WalletHistoryLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? currency = null,Object? types = null,Object? from = freezed,Object? to = freezed,Object? items = null,Object? page = null,Object? totalPages = null,Object? failureOption = null,Object? isFetching = null,Object? isLoadingMore = null,}) {
|
||||
return _then(_WalletHistoryLoaderState(
|
||||
currency: null == currency ? _self.currency : currency // ignore: cast_nullable_to_non_nullable
|
||||
as WalletCurrency,types: null == types ? _self._types : types // ignore: cast_nullable_to_non_nullable
|
||||
as List<WalletTransactionType>,from: freezed == from ? _self.from : from // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,to: freezed == to ? _self.to : to // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,items: null == items ? _self._items : items // ignore: cast_nullable_to_non_nullable
|
||||
as List<WalletTransaction>,page: null == page ? _self.page : page // ignore: cast_nullable_to_non_nullable
|
||||
as int,totalPages: null == totalPages ? _self.totalPages : totalPages // ignore: cast_nullable_to_non_nullable
|
||||
as int,failureOption: null == failureOption ? _self.failureOption : failureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,isFetching: null == isFetching ? _self.isFetching : isFetching // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isLoadingMore: null == isLoadingMore ? _self.isLoadingMore : isLoadingMore // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -0,0 +1,18 @@
|
||||
part of 'wallet_history_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class WalletHistoryLoaderEvent with _$WalletHistoryLoaderEvent {
|
||||
const factory WalletHistoryLoaderEvent.currencyChanged(
|
||||
WalletCurrency currency,
|
||||
) = _CurrencyChanged;
|
||||
|
||||
const factory WalletHistoryLoaderEvent.filterChanged({
|
||||
required List<WalletTransactionType> types,
|
||||
DateTime? from,
|
||||
DateTime? to,
|
||||
}) = _FilterChanged;
|
||||
|
||||
const factory WalletHistoryLoaderEvent.refreshed() = _Refreshed;
|
||||
|
||||
const factory WalletHistoryLoaderEvent.loadedMore() = _LoadedMore;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
part of 'wallet_history_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class WalletHistoryLoaderState with _$WalletHistoryLoaderState {
|
||||
const WalletHistoryLoaderState._();
|
||||
|
||||
const factory WalletHistoryLoaderState({
|
||||
required WalletCurrency currency,
|
||||
required List<WalletTransactionType> types,
|
||||
DateTime? from,
|
||||
DateTime? to,
|
||||
required List<WalletTransaction> items,
|
||||
required int page,
|
||||
required int totalPages,
|
||||
required Option<WalletFailure> failureOption,
|
||||
@Default(false) bool isFetching,
|
||||
@Default(false) bool isLoadingMore,
|
||||
}) = _WalletHistoryLoaderState;
|
||||
|
||||
factory WalletHistoryLoaderState.initial() => WalletHistoryLoaderState(
|
||||
currency: WalletCurrency.point,
|
||||
types: const [],
|
||||
items: const [],
|
||||
page: 0,
|
||||
totalPages: 0,
|
||||
failureOption: none(),
|
||||
);
|
||||
|
||||
bool get hasMore => page < totalPages;
|
||||
|
||||
bool get hasFilter => types.isNotEmpty || from != null || to != null;
|
||||
|
||||
/// Identitas query aktif, untuk membuang jawaban yang sudah basi.
|
||||
String get query => '${currency.apiValue}|${types.join(',')}|$from|$to';
|
||||
}
|
||||
Reference in New Issue
Block a user