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,87 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../common/function/app_function.dart';
|
||||
import '../../../domain/wallet/wallet.dart';
|
||||
|
||||
part 'exchange_form_event.dart';
|
||||
part 'exchange_form_state.dart';
|
||||
part 'exchange_form_bloc.freezed.dart';
|
||||
|
||||
@injectable
|
||||
class ExchangeFormBloc extends Bloc<ExchangeFormEvent, ExchangeFormState> {
|
||||
final IWalletRepository _repository;
|
||||
|
||||
ExchangeFormBloc(this._repository) : super(ExchangeFormState.initial()) {
|
||||
on<ExchangeFormEvent>(_onExchangeFormEvent);
|
||||
}
|
||||
|
||||
Future<void> _onExchangeFormEvent(
|
||||
ExchangeFormEvent event,
|
||||
Emitter<ExchangeFormState> emit,
|
||||
) {
|
||||
return event.map(
|
||||
// UI men-debounce ketikan sebelum mengirim event ini.
|
||||
coinsChanged: (e) async {
|
||||
emit(
|
||||
state.copyWith(
|
||||
coins: e.coins,
|
||||
preview: null,
|
||||
previewFailureOption: none(),
|
||||
idempotencyKey: null,
|
||||
isPreviewing: e.coins > 0,
|
||||
),
|
||||
);
|
||||
if (e.coins <= 0) return;
|
||||
|
||||
final result = await _repository.previewExchange(coins: e.coins);
|
||||
// Customer sudah mengetik angka lain.
|
||||
if (state.coins != e.coins) return;
|
||||
|
||||
emit(
|
||||
result
|
||||
.fold(
|
||||
(f) => state.copyWith(previewFailureOption: optionOf(f)),
|
||||
(preview) => state.copyWith(preview: preview),
|
||||
)
|
||||
.copyWith(isPreviewing: false),
|
||||
);
|
||||
},
|
||||
submitted: (e) async {
|
||||
// Key baru untuk setiap konfirmasi, kecuali mengulang request yang
|
||||
// sebelumnya gagal karena jaringan.
|
||||
final key = state.idempotencyKey ?? generateUuidV4();
|
||||
emit(
|
||||
state.copyWith(
|
||||
isSubmitting: true,
|
||||
idempotencyKey: key,
|
||||
failureOption: none(),
|
||||
),
|
||||
);
|
||||
|
||||
final result = await _repository.exchange(
|
||||
coins: state.coins,
|
||||
pin: e.pin,
|
||||
idempotencyKey: key,
|
||||
);
|
||||
|
||||
emit(
|
||||
result
|
||||
.fold(
|
||||
(f) => state.copyWith(
|
||||
failureOption: optionOf(f),
|
||||
idempotencyKey: f.isNetworkError ? key : null,
|
||||
),
|
||||
(exchangeResult) => state.copyWith(
|
||||
result: exchangeResult,
|
||||
idempotencyKey: null,
|
||||
),
|
||||
)
|
||||
.copyWith(isSubmitting: false),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,650 @@
|
||||
// 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 'exchange_form_bloc.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$ExchangeFormEvent {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is ExchangeFormEvent);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ExchangeFormEvent()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class $ExchangeFormEventCopyWith<$Res> {
|
||||
$ExchangeFormEventCopyWith(ExchangeFormEvent _, $Res Function(ExchangeFormEvent) __);
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [ExchangeFormEvent].
|
||||
extension ExchangeFormEventPatterns on ExchangeFormEvent {
|
||||
/// 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( _CoinsChanged value)? coinsChanged,TResult Function( _Submitted value)? submitted,required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _CoinsChanged() when coinsChanged != null:
|
||||
return coinsChanged(_that);case _Submitted() when submitted != null:
|
||||
return submitted(_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( _CoinsChanged value) coinsChanged,required TResult Function( _Submitted value) submitted,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _CoinsChanged():
|
||||
return coinsChanged(_that);case _Submitted():
|
||||
return submitted(_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( _CoinsChanged value)? coinsChanged,TResult? Function( _Submitted value)? submitted,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _CoinsChanged() when coinsChanged != null:
|
||||
return coinsChanged(_that);case _Submitted() when submitted != null:
|
||||
return submitted(_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( int coins)? coinsChanged,TResult Function( String pin)? submitted,required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _CoinsChanged() when coinsChanged != null:
|
||||
return coinsChanged(_that.coins);case _Submitted() when submitted != null:
|
||||
return submitted(_that.pin);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( int coins) coinsChanged,required TResult Function( String pin) submitted,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _CoinsChanged():
|
||||
return coinsChanged(_that.coins);case _Submitted():
|
||||
return submitted(_that.pin);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( int coins)? coinsChanged,TResult? Function( String pin)? submitted,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _CoinsChanged() when coinsChanged != null:
|
||||
return coinsChanged(_that.coins);case _Submitted() when submitted != null:
|
||||
return submitted(_that.pin);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _CoinsChanged implements ExchangeFormEvent {
|
||||
const _CoinsChanged(this.coins);
|
||||
|
||||
|
||||
final int coins;
|
||||
|
||||
/// Create a copy of ExchangeFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$CoinsChangedCopyWith<_CoinsChanged> get copyWith => __$CoinsChangedCopyWithImpl<_CoinsChanged>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _CoinsChanged&&(identical(other.coins, coins) || other.coins == coins));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,coins);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ExchangeFormEvent.coinsChanged(coins: $coins)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$CoinsChangedCopyWith<$Res> implements $ExchangeFormEventCopyWith<$Res> {
|
||||
factory _$CoinsChangedCopyWith(_CoinsChanged value, $Res Function(_CoinsChanged) _then) = __$CoinsChangedCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
int coins
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$CoinsChangedCopyWithImpl<$Res>
|
||||
implements _$CoinsChangedCopyWith<$Res> {
|
||||
__$CoinsChangedCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _CoinsChanged _self;
|
||||
final $Res Function(_CoinsChanged) _then;
|
||||
|
||||
/// Create a copy of ExchangeFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? coins = null,}) {
|
||||
return _then(_CoinsChanged(
|
||||
null == coins ? _self.coins : coins // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _Submitted implements ExchangeFormEvent {
|
||||
const _Submitted(this.pin);
|
||||
|
||||
|
||||
final String pin;
|
||||
|
||||
/// Create a copy of ExchangeFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$SubmittedCopyWith<_Submitted> get copyWith => __$SubmittedCopyWithImpl<_Submitted>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Submitted&&(identical(other.pin, pin) || other.pin == pin));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,pin);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ExchangeFormEvent.submitted(pin: $pin)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$SubmittedCopyWith<$Res> implements $ExchangeFormEventCopyWith<$Res> {
|
||||
factory _$SubmittedCopyWith(_Submitted value, $Res Function(_Submitted) _then) = __$SubmittedCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String pin
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$SubmittedCopyWithImpl<$Res>
|
||||
implements _$SubmittedCopyWith<$Res> {
|
||||
__$SubmittedCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _Submitted _self;
|
||||
final $Res Function(_Submitted) _then;
|
||||
|
||||
/// Create a copy of ExchangeFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? pin = null,}) {
|
||||
return _then(_Submitted(
|
||||
null == pin ? _self.pin : pin // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$ExchangeFormState {
|
||||
|
||||
int get coins; ExchangePreview? get preview; Option<WalletFailure> get previewFailureOption; bool get isPreviewing; ExchangeResult? get result; Option<WalletFailure> get failureOption; bool get isSubmitting; String? get idempotencyKey;
|
||||
/// Create a copy of ExchangeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$ExchangeFormStateCopyWith<ExchangeFormState> get copyWith => _$ExchangeFormStateCopyWithImpl<ExchangeFormState>(this as ExchangeFormState, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
final _this = this as ExchangeFormState;
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is ExchangeFormState&&(identical(other.coins, _this.coins) || other.coins == _this.coins)&&(identical(other.preview, _this.preview) || other.preview == _this.preview)&&(identical(other.previewFailureOption, _this.previewFailureOption) || other.previewFailureOption == _this.previewFailureOption)&&(identical(other.isPreviewing, _this.isPreviewing) || other.isPreviewing == _this.isPreviewing)&&(identical(other.result, _this.result) || other.result == _this.result)&&(identical(other.failureOption, _this.failureOption) || other.failureOption == _this.failureOption)&&(identical(other.isSubmitting, _this.isSubmitting) || other.isSubmitting == _this.isSubmitting)&&(identical(other.idempotencyKey, _this.idempotencyKey) || other.idempotencyKey == _this.idempotencyKey));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as ExchangeFormState;
|
||||
return Object.hash(runtimeType,_this.coins,_this.preview,_this.previewFailureOption,_this.isPreviewing,_this.result,_this.failureOption,_this.isSubmitting,_this.idempotencyKey);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as ExchangeFormState;
|
||||
return 'ExchangeFormState(coins: ${_this.coins}, preview: ${_this.preview}, previewFailureOption: ${_this.previewFailureOption}, isPreviewing: ${_this.isPreviewing}, result: ${_this.result}, failureOption: ${_this.failureOption}, isSubmitting: ${_this.isSubmitting}, idempotencyKey: ${_this.idempotencyKey})';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $ExchangeFormStateCopyWith<$Res> {
|
||||
factory $ExchangeFormStateCopyWith(ExchangeFormState value, $Res Function(ExchangeFormState) _then) = _$ExchangeFormStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
int coins, ExchangePreview? preview, Option<WalletFailure> previewFailureOption, bool isPreviewing, ExchangeResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey
|
||||
});
|
||||
|
||||
|
||||
$ExchangePreviewCopyWith<$Res>? get preview;$ExchangeResultCopyWith<$Res>? get result;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$ExchangeFormStateCopyWithImpl<$Res>
|
||||
implements $ExchangeFormStateCopyWith<$Res> {
|
||||
_$ExchangeFormStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final ExchangeFormState _self;
|
||||
final $Res Function(ExchangeFormState) _then;
|
||||
|
||||
/// Create a copy of ExchangeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? coins = null,Object? preview = freezed,Object? previewFailureOption = null,Object? isPreviewing = null,Object? result = freezed,Object? failureOption = null,Object? isSubmitting = null,Object? idempotencyKey = freezed,}) {
|
||||
return _then(ExchangeFormState(
|
||||
coins: null == coins ? _self.coins : coins // ignore: cast_nullable_to_non_nullable
|
||||
as int,preview: freezed == preview ? _self.preview : preview // ignore: cast_nullable_to_non_nullable
|
||||
as ExchangePreview?,previewFailureOption: null == previewFailureOption ? _self.previewFailureOption : previewFailureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,isPreviewing: null == isPreviewing ? _self.isPreviewing : isPreviewing // ignore: cast_nullable_to_non_nullable
|
||||
as bool,result: freezed == result ? _self.result : result // ignore: cast_nullable_to_non_nullable
|
||||
as ExchangeResult?,failureOption: null == failureOption ? _self.failureOption : failureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,isSubmitting: null == isSubmitting ? _self.isSubmitting : isSubmitting // ignore: cast_nullable_to_non_nullable
|
||||
as bool,idempotencyKey: freezed == idempotencyKey ? _self.idempotencyKey : idempotencyKey // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
));
|
||||
}
|
||||
/// Create a copy of ExchangeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$ExchangePreviewCopyWith<$Res>? get preview {
|
||||
if (_self.preview == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $ExchangePreviewCopyWith<$Res>(_self.preview!, (value) {
|
||||
return _then(_self.copyWith(preview: value));
|
||||
});
|
||||
}/// Create a copy of ExchangeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$ExchangeResultCopyWith<$Res>? get result {
|
||||
if (_self.result == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $ExchangeResultCopyWith<$Res>(_self.result!, (value) {
|
||||
return _then(_self.copyWith(result: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [ExchangeFormState].
|
||||
extension ExchangeFormStatePatterns on ExchangeFormState {
|
||||
/// 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( _ExchangeFormState value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ExchangeFormState() 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( _ExchangeFormState value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ExchangeFormState():
|
||||
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( _ExchangeFormState value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ExchangeFormState() 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( int coins, ExchangePreview? preview, Option<WalletFailure> previewFailureOption, bool isPreviewing, ExchangeResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _ExchangeFormState() when $default != null:
|
||||
return $default(_that.coins,_that.preview,_that.previewFailureOption,_that.isPreviewing,_that.result,_that.failureOption,_that.isSubmitting,_that.idempotencyKey);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( int coins, ExchangePreview? preview, Option<WalletFailure> previewFailureOption, bool isPreviewing, ExchangeResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _ExchangeFormState():
|
||||
return $default(_that.coins,_that.preview,_that.previewFailureOption,_that.isPreviewing,_that.result,_that.failureOption,_that.isSubmitting,_that.idempotencyKey);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( int coins, ExchangePreview? preview, Option<WalletFailure> previewFailureOption, bool isPreviewing, ExchangeResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _ExchangeFormState() when $default != null:
|
||||
return $default(_that.coins,_that.preview,_that.previewFailureOption,_that.isPreviewing,_that.result,_that.failureOption,_that.isSubmitting,_that.idempotencyKey);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _ExchangeFormState extends ExchangeFormState {
|
||||
const _ExchangeFormState({required this.coins, this.preview, required this.previewFailureOption, this.isPreviewing = false, this.result, required this.failureOption, this.isSubmitting = false, this.idempotencyKey}): super._();
|
||||
|
||||
|
||||
@override final int coins;
|
||||
@override final ExchangePreview? preview;
|
||||
@override final Option<WalletFailure> previewFailureOption;
|
||||
@override@JsonKey() final bool isPreviewing;
|
||||
@override final ExchangeResult? result;
|
||||
@override final Option<WalletFailure> failureOption;
|
||||
@override@JsonKey() final bool isSubmitting;
|
||||
@override final String? idempotencyKey;
|
||||
|
||||
/// Create a copy of ExchangeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$ExchangeFormStateCopyWith<_ExchangeFormState> get copyWith => __$ExchangeFormStateCopyWithImpl<_ExchangeFormState>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ExchangeFormState&&(identical(other.coins, coins) || other.coins == coins)&&(identical(other.preview, preview) || other.preview == preview)&&(identical(other.previewFailureOption, previewFailureOption) || other.previewFailureOption == previewFailureOption)&&(identical(other.isPreviewing, isPreviewing) || other.isPreviewing == isPreviewing)&&(identical(other.result, result) || other.result == result)&&(identical(other.failureOption, failureOption) || other.failureOption == failureOption)&&(identical(other.isSubmitting, isSubmitting) || other.isSubmitting == isSubmitting)&&(identical(other.idempotencyKey, idempotencyKey) || other.idempotencyKey == idempotencyKey));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,coins,preview,previewFailureOption,isPreviewing,result,failureOption,isSubmitting,idempotencyKey);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ExchangeFormState(coins: $coins, preview: $preview, previewFailureOption: $previewFailureOption, isPreviewing: $isPreviewing, result: $result, failureOption: $failureOption, isSubmitting: $isSubmitting, idempotencyKey: $idempotencyKey)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$ExchangeFormStateCopyWith<$Res> implements $ExchangeFormStateCopyWith<$Res> {
|
||||
factory _$ExchangeFormStateCopyWith(_ExchangeFormState value, $Res Function(_ExchangeFormState) _then) = __$ExchangeFormStateCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
int coins, ExchangePreview? preview, Option<WalletFailure> previewFailureOption, bool isPreviewing, ExchangeResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey
|
||||
});
|
||||
|
||||
|
||||
@override $ExchangePreviewCopyWith<$Res>? get preview;@override $ExchangeResultCopyWith<$Res>? get result;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$ExchangeFormStateCopyWithImpl<$Res>
|
||||
implements _$ExchangeFormStateCopyWith<$Res> {
|
||||
__$ExchangeFormStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _ExchangeFormState _self;
|
||||
final $Res Function(_ExchangeFormState) _then;
|
||||
|
||||
/// Create a copy of ExchangeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? coins = null,Object? preview = freezed,Object? previewFailureOption = null,Object? isPreviewing = null,Object? result = freezed,Object? failureOption = null,Object? isSubmitting = null,Object? idempotencyKey = freezed,}) {
|
||||
return _then(_ExchangeFormState(
|
||||
coins: null == coins ? _self.coins : coins // ignore: cast_nullable_to_non_nullable
|
||||
as int,preview: freezed == preview ? _self.preview : preview // ignore: cast_nullable_to_non_nullable
|
||||
as ExchangePreview?,previewFailureOption: null == previewFailureOption ? _self.previewFailureOption : previewFailureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,isPreviewing: null == isPreviewing ? _self.isPreviewing : isPreviewing // ignore: cast_nullable_to_non_nullable
|
||||
as bool,result: freezed == result ? _self.result : result // ignore: cast_nullable_to_non_nullable
|
||||
as ExchangeResult?,failureOption: null == failureOption ? _self.failureOption : failureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,isSubmitting: null == isSubmitting ? _self.isSubmitting : isSubmitting // ignore: cast_nullable_to_non_nullable
|
||||
as bool,idempotencyKey: freezed == idempotencyKey ? _self.idempotencyKey : idempotencyKey // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
));
|
||||
}
|
||||
|
||||
/// Create a copy of ExchangeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$ExchangePreviewCopyWith<$Res>? get preview {
|
||||
if (_self.preview == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $ExchangePreviewCopyWith<$Res>(_self.preview!, (value) {
|
||||
return _then(_self.copyWith(preview: value));
|
||||
});
|
||||
}/// Create a copy of ExchangeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$ExchangeResultCopyWith<$Res>? get result {
|
||||
if (_self.result == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $ExchangeResultCopyWith<$Res>(_self.result!, (value) {
|
||||
return _then(_self.copyWith(result: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -0,0 +1,9 @@
|
||||
part of 'exchange_form_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class ExchangeFormEvent with _$ExchangeFormEvent {
|
||||
const factory ExchangeFormEvent.coinsChanged(int coins) = _CoinsChanged;
|
||||
|
||||
/// [pin] hanya diteruskan ke API, tidak disimpan di state.
|
||||
const factory ExchangeFormEvent.submitted(String pin) = _Submitted;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
part of 'exchange_form_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class ExchangeFormState with _$ExchangeFormState {
|
||||
const ExchangeFormState._();
|
||||
|
||||
const factory ExchangeFormState({
|
||||
required int coins,
|
||||
ExchangePreview? preview,
|
||||
required Option<WalletFailure> previewFailureOption,
|
||||
@Default(false) bool isPreviewing,
|
||||
ExchangeResult? result,
|
||||
required Option<WalletFailure> failureOption,
|
||||
@Default(false) bool isSubmitting,
|
||||
String? idempotencyKey,
|
||||
}) = _ExchangeFormState;
|
||||
|
||||
factory ExchangeFormState.initial() => ExchangeFormState(
|
||||
coins: 0,
|
||||
previewFailureOption: none(),
|
||||
failureOption: none(),
|
||||
);
|
||||
|
||||
bool get canSubmit =>
|
||||
!isPreviewing &&
|
||||
!isSubmitting &&
|
||||
preview != null &&
|
||||
preview!.valid &&
|
||||
preview!.coins == coins;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
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 'payment_code_form_event.dart';
|
||||
part 'payment_code_form_state.dart';
|
||||
part 'payment_code_form_bloc.freezed.dart';
|
||||
|
||||
@injectable
|
||||
class PaymentCodeFormBloc
|
||||
extends Bloc<PaymentCodeFormEvent, PaymentCodeFormState> {
|
||||
final IWalletRepository _repository;
|
||||
|
||||
PaymentCodeFormBloc(this._repository)
|
||||
: super(PaymentCodeFormState.initial()) {
|
||||
on<PaymentCodeFormEvent>(_onPaymentCodeFormEvent);
|
||||
}
|
||||
|
||||
Future<void> _onPaymentCodeFormEvent(
|
||||
PaymentCodeFormEvent event,
|
||||
Emitter<PaymentCodeFormState> emit,
|
||||
) {
|
||||
return event.map(
|
||||
submitted: (e) async {
|
||||
emit(state.copyWith(isSubmitting: true, failureOption: none()));
|
||||
|
||||
final result = await _repository.createPaymentCode(pin: e.pin);
|
||||
|
||||
emit(
|
||||
result
|
||||
.fold(
|
||||
(f) => state.copyWith(failureOption: optionOf(f)),
|
||||
(code) => state.copyWith(paymentCode: code),
|
||||
)
|
||||
.copyWith(isSubmitting: false),
|
||||
);
|
||||
},
|
||||
expired: (e) async => emit(state.copyWith(paymentCode: null)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,575 @@
|
||||
// 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 'payment_code_form_bloc.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$PaymentCodeFormEvent {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is PaymentCodeFormEvent);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PaymentCodeFormEvent()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class $PaymentCodeFormEventCopyWith<$Res> {
|
||||
$PaymentCodeFormEventCopyWith(PaymentCodeFormEvent _, $Res Function(PaymentCodeFormEvent) __);
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [PaymentCodeFormEvent].
|
||||
extension PaymentCodeFormEventPatterns on PaymentCodeFormEvent {
|
||||
/// 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( _Submitted value)? submitted,TResult Function( _Expired value)? expired,required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _Submitted() when submitted != null:
|
||||
return submitted(_that);case _Expired() when expired != null:
|
||||
return expired(_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( _Submitted value) submitted,required TResult Function( _Expired value) expired,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _Submitted():
|
||||
return submitted(_that);case _Expired():
|
||||
return expired(_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( _Submitted value)? submitted,TResult? Function( _Expired value)? expired,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _Submitted() when submitted != null:
|
||||
return submitted(_that);case _Expired() when expired != null:
|
||||
return expired(_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( String pin)? submitted,TResult Function()? expired,required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _Submitted() when submitted != null:
|
||||
return submitted(_that.pin);case _Expired() when expired != null:
|
||||
return expired();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( String pin) submitted,required TResult Function() expired,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _Submitted():
|
||||
return submitted(_that.pin);case _Expired():
|
||||
return expired();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( String pin)? submitted,TResult? Function()? expired,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _Submitted() when submitted != null:
|
||||
return submitted(_that.pin);case _Expired() when expired != null:
|
||||
return expired();case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _Submitted implements PaymentCodeFormEvent {
|
||||
const _Submitted(this.pin);
|
||||
|
||||
|
||||
final String pin;
|
||||
|
||||
/// Create a copy of PaymentCodeFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$SubmittedCopyWith<_Submitted> get copyWith => __$SubmittedCopyWithImpl<_Submitted>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Submitted&&(identical(other.pin, pin) || other.pin == pin));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,pin);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PaymentCodeFormEvent.submitted(pin: $pin)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$SubmittedCopyWith<$Res> implements $PaymentCodeFormEventCopyWith<$Res> {
|
||||
factory _$SubmittedCopyWith(_Submitted value, $Res Function(_Submitted) _then) = __$SubmittedCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String pin
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$SubmittedCopyWithImpl<$Res>
|
||||
implements _$SubmittedCopyWith<$Res> {
|
||||
__$SubmittedCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _Submitted _self;
|
||||
final $Res Function(_Submitted) _then;
|
||||
|
||||
/// Create a copy of PaymentCodeFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? pin = null,}) {
|
||||
return _then(_Submitted(
|
||||
null == pin ? _self.pin : pin // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _Expired implements PaymentCodeFormEvent {
|
||||
const _Expired();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Expired);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PaymentCodeFormEvent.expired()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// @nodoc
|
||||
mixin _$PaymentCodeFormState {
|
||||
|
||||
PaymentCode? get paymentCode; Option<WalletFailure> get failureOption; bool get isSubmitting;
|
||||
/// Create a copy of PaymentCodeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$PaymentCodeFormStateCopyWith<PaymentCodeFormState> get copyWith => _$PaymentCodeFormStateCopyWithImpl<PaymentCodeFormState>(this as PaymentCodeFormState, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
final _this = this as PaymentCodeFormState;
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is PaymentCodeFormState&&(identical(other.paymentCode, _this.paymentCode) || other.paymentCode == _this.paymentCode)&&(identical(other.failureOption, _this.failureOption) || other.failureOption == _this.failureOption)&&(identical(other.isSubmitting, _this.isSubmitting) || other.isSubmitting == _this.isSubmitting));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as PaymentCodeFormState;
|
||||
return Object.hash(runtimeType,_this.paymentCode,_this.failureOption,_this.isSubmitting);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as PaymentCodeFormState;
|
||||
return 'PaymentCodeFormState(paymentCode: ${_this.paymentCode}, failureOption: ${_this.failureOption}, isSubmitting: ${_this.isSubmitting})';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $PaymentCodeFormStateCopyWith<$Res> {
|
||||
factory $PaymentCodeFormStateCopyWith(PaymentCodeFormState value, $Res Function(PaymentCodeFormState) _then) = _$PaymentCodeFormStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
PaymentCode? paymentCode, Option<WalletFailure> failureOption, bool isSubmitting
|
||||
});
|
||||
|
||||
|
||||
$PaymentCodeCopyWith<$Res>? get paymentCode;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$PaymentCodeFormStateCopyWithImpl<$Res>
|
||||
implements $PaymentCodeFormStateCopyWith<$Res> {
|
||||
_$PaymentCodeFormStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final PaymentCodeFormState _self;
|
||||
final $Res Function(PaymentCodeFormState) _then;
|
||||
|
||||
/// Create a copy of PaymentCodeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? paymentCode = freezed,Object? failureOption = null,Object? isSubmitting = null,}) {
|
||||
return _then(PaymentCodeFormState(
|
||||
paymentCode: freezed == paymentCode ? _self.paymentCode : paymentCode // ignore: cast_nullable_to_non_nullable
|
||||
as PaymentCode?,failureOption: null == failureOption ? _self.failureOption : failureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,isSubmitting: null == isSubmitting ? _self.isSubmitting : isSubmitting // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
/// Create a copy of PaymentCodeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$PaymentCodeCopyWith<$Res>? get paymentCode {
|
||||
if (_self.paymentCode == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $PaymentCodeCopyWith<$Res>(_self.paymentCode!, (value) {
|
||||
return _then(_self.copyWith(paymentCode: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [PaymentCodeFormState].
|
||||
extension PaymentCodeFormStatePatterns on PaymentCodeFormState {
|
||||
/// 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( _PaymentCodeFormState value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _PaymentCodeFormState() 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( _PaymentCodeFormState value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _PaymentCodeFormState():
|
||||
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( _PaymentCodeFormState value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _PaymentCodeFormState() 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( PaymentCode? paymentCode, Option<WalletFailure> failureOption, bool isSubmitting)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _PaymentCodeFormState() when $default != null:
|
||||
return $default(_that.paymentCode,_that.failureOption,_that.isSubmitting);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( PaymentCode? paymentCode, Option<WalletFailure> failureOption, bool isSubmitting) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _PaymentCodeFormState():
|
||||
return $default(_that.paymentCode,_that.failureOption,_that.isSubmitting);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( PaymentCode? paymentCode, Option<WalletFailure> failureOption, bool isSubmitting)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _PaymentCodeFormState() when $default != null:
|
||||
return $default(_that.paymentCode,_that.failureOption,_that.isSubmitting);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _PaymentCodeFormState implements PaymentCodeFormState {
|
||||
const _PaymentCodeFormState({this.paymentCode, required this.failureOption, this.isSubmitting = false});
|
||||
|
||||
|
||||
@override final PaymentCode? paymentCode;
|
||||
@override final Option<WalletFailure> failureOption;
|
||||
@override@JsonKey() final bool isSubmitting;
|
||||
|
||||
/// Create a copy of PaymentCodeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$PaymentCodeFormStateCopyWith<_PaymentCodeFormState> get copyWith => __$PaymentCodeFormStateCopyWithImpl<_PaymentCodeFormState>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _PaymentCodeFormState&&(identical(other.paymentCode, paymentCode) || other.paymentCode == paymentCode)&&(identical(other.failureOption, failureOption) || other.failureOption == failureOption)&&(identical(other.isSubmitting, isSubmitting) || other.isSubmitting == isSubmitting));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,paymentCode,failureOption,isSubmitting);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PaymentCodeFormState(paymentCode: $paymentCode, failureOption: $failureOption, isSubmitting: $isSubmitting)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$PaymentCodeFormStateCopyWith<$Res> implements $PaymentCodeFormStateCopyWith<$Res> {
|
||||
factory _$PaymentCodeFormStateCopyWith(_PaymentCodeFormState value, $Res Function(_PaymentCodeFormState) _then) = __$PaymentCodeFormStateCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
PaymentCode? paymentCode, Option<WalletFailure> failureOption, bool isSubmitting
|
||||
});
|
||||
|
||||
|
||||
@override $PaymentCodeCopyWith<$Res>? get paymentCode;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$PaymentCodeFormStateCopyWithImpl<$Res>
|
||||
implements _$PaymentCodeFormStateCopyWith<$Res> {
|
||||
__$PaymentCodeFormStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _PaymentCodeFormState _self;
|
||||
final $Res Function(_PaymentCodeFormState) _then;
|
||||
|
||||
/// Create a copy of PaymentCodeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? paymentCode = freezed,Object? failureOption = null,Object? isSubmitting = null,}) {
|
||||
return _then(_PaymentCodeFormState(
|
||||
paymentCode: freezed == paymentCode ? _self.paymentCode : paymentCode // ignore: cast_nullable_to_non_nullable
|
||||
as PaymentCode?,failureOption: null == failureOption ? _self.failureOption : failureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,isSubmitting: null == isSubmitting ? _self.isSubmitting : isSubmitting // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
|
||||
/// Create a copy of PaymentCodeFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$PaymentCodeCopyWith<$Res>? get paymentCode {
|
||||
if (_self.paymentCode == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $PaymentCodeCopyWith<$Res>(_self.paymentCode!, (value) {
|
||||
return _then(_self.copyWith(paymentCode: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -0,0 +1,9 @@
|
||||
part of 'payment_code_form_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class PaymentCodeFormEvent with _$PaymentCodeFormEvent {
|
||||
/// [pin] hanya diteruskan ke API, tidak disimpan di state.
|
||||
const factory PaymentCodeFormEvent.submitted(String pin) = _Submitted;
|
||||
|
||||
const factory PaymentCodeFormEvent.expired() = _Expired;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
part of 'payment_code_form_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class PaymentCodeFormState with _$PaymentCodeFormState {
|
||||
const factory PaymentCodeFormState({
|
||||
PaymentCode? paymentCode,
|
||||
required Option<WalletFailure> failureOption,
|
||||
@Default(false) bool isSubmitting,
|
||||
}) = _PaymentCodeFormState;
|
||||
|
||||
factory PaymentCodeFormState.initial() =>
|
||||
PaymentCodeFormState(failureOption: none());
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../common/function/app_function.dart';
|
||||
import '../../../domain/wallet/wallet.dart';
|
||||
|
||||
part 'transfer_form_event.dart';
|
||||
part 'transfer_form_state.dart';
|
||||
part 'transfer_form_bloc.freezed.dart';
|
||||
|
||||
@injectable
|
||||
class TransferFormBloc extends Bloc<TransferFormEvent, TransferFormState> {
|
||||
final IWalletRepository _repository;
|
||||
|
||||
TransferFormBloc(this._repository) : super(TransferFormState.initial()) {
|
||||
on<TransferFormEvent>(_onTransferFormEvent);
|
||||
}
|
||||
|
||||
Future<void> _onTransferFormEvent(
|
||||
TransferFormEvent event,
|
||||
Emitter<TransferFormState> emit,
|
||||
) {
|
||||
return event.map(
|
||||
currencyChanged: (e) async => emit(
|
||||
state.copyWith(
|
||||
currency: e.currency,
|
||||
idempotencyKey: null,
|
||||
failureOption: none(),
|
||||
),
|
||||
),
|
||||
phoneChanged: (e) async => emit(
|
||||
state.copyWith(
|
||||
phone: e.phone,
|
||||
recipient: null,
|
||||
recipientFailureOption: none(),
|
||||
idempotencyKey: null,
|
||||
failureOption: none(),
|
||||
),
|
||||
),
|
||||
amountChanged: (e) async => emit(
|
||||
state.copyWith(
|
||||
amount: e.amount,
|
||||
idempotencyKey: null,
|
||||
failureOption: none(),
|
||||
),
|
||||
),
|
||||
recipientChecked: (e) async {
|
||||
final phone = state.phone;
|
||||
emit(
|
||||
state.copyWith(
|
||||
isCheckingRecipient: true,
|
||||
recipient: null,
|
||||
recipientFailureOption: none(),
|
||||
),
|
||||
);
|
||||
|
||||
final result = await _repository.checkRecipient(phone: phone);
|
||||
if (state.phone != phone) return;
|
||||
|
||||
emit(
|
||||
result
|
||||
.fold(
|
||||
(f) => state.copyWith(recipientFailureOption: optionOf(f)),
|
||||
(recipient) => state.copyWith(recipient: recipient),
|
||||
)
|
||||
.copyWith(isCheckingRecipient: false),
|
||||
);
|
||||
},
|
||||
submitted: (e) async {
|
||||
// Key baru untuk setiap konfirmasi, kecuali mengulang request yang
|
||||
// sebelumnya gagal karena jaringan.
|
||||
final key = state.idempotencyKey ?? generateUuidV4();
|
||||
emit(
|
||||
state.copyWith(
|
||||
isSubmitting: true,
|
||||
idempotencyKey: key,
|
||||
failureOption: none(),
|
||||
),
|
||||
);
|
||||
|
||||
final result = await _repository.transfer(
|
||||
currency: state.currency,
|
||||
amount: state.amount,
|
||||
recipientPhone: state.phone,
|
||||
pin: e.pin,
|
||||
idempotencyKey: key,
|
||||
);
|
||||
|
||||
emit(
|
||||
result
|
||||
.fold(
|
||||
(f) => state.copyWith(
|
||||
failureOption: optionOf(f),
|
||||
idempotencyKey: f.isNetworkError ? key : null,
|
||||
),
|
||||
(transferResult) => state.copyWith(
|
||||
result: transferResult,
|
||||
idempotencyKey: null,
|
||||
),
|
||||
)
|
||||
.copyWith(isSubmitting: false),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,842 @@
|
||||
// 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 'transfer_form_bloc.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$TransferFormEvent {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is TransferFormEvent);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TransferFormEvent()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class $TransferFormEventCopyWith<$Res> {
|
||||
$TransferFormEventCopyWith(TransferFormEvent _, $Res Function(TransferFormEvent) __);
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [TransferFormEvent].
|
||||
extension TransferFormEventPatterns on TransferFormEvent {
|
||||
/// 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( _PhoneChanged value)? phoneChanged,TResult Function( _AmountChanged value)? amountChanged,TResult Function( _RecipientChecked value)? recipientChecked,TResult Function( _Submitted value)? submitted,required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _CurrencyChanged() when currencyChanged != null:
|
||||
return currencyChanged(_that);case _PhoneChanged() when phoneChanged != null:
|
||||
return phoneChanged(_that);case _AmountChanged() when amountChanged != null:
|
||||
return amountChanged(_that);case _RecipientChecked() when recipientChecked != null:
|
||||
return recipientChecked(_that);case _Submitted() when submitted != null:
|
||||
return submitted(_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( _PhoneChanged value) phoneChanged,required TResult Function( _AmountChanged value) amountChanged,required TResult Function( _RecipientChecked value) recipientChecked,required TResult Function( _Submitted value) submitted,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _CurrencyChanged():
|
||||
return currencyChanged(_that);case _PhoneChanged():
|
||||
return phoneChanged(_that);case _AmountChanged():
|
||||
return amountChanged(_that);case _RecipientChecked():
|
||||
return recipientChecked(_that);case _Submitted():
|
||||
return submitted(_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( _PhoneChanged value)? phoneChanged,TResult? Function( _AmountChanged value)? amountChanged,TResult? Function( _RecipientChecked value)? recipientChecked,TResult? Function( _Submitted value)? submitted,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _CurrencyChanged() when currencyChanged != null:
|
||||
return currencyChanged(_that);case _PhoneChanged() when phoneChanged != null:
|
||||
return phoneChanged(_that);case _AmountChanged() when amountChanged != null:
|
||||
return amountChanged(_that);case _RecipientChecked() when recipientChecked != null:
|
||||
return recipientChecked(_that);case _Submitted() when submitted != null:
|
||||
return submitted(_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( String phone)? phoneChanged,TResult Function( int amount)? amountChanged,TResult Function()? recipientChecked,TResult Function( String pin)? submitted,required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _CurrencyChanged() when currencyChanged != null:
|
||||
return currencyChanged(_that.currency);case _PhoneChanged() when phoneChanged != null:
|
||||
return phoneChanged(_that.phone);case _AmountChanged() when amountChanged != null:
|
||||
return amountChanged(_that.amount);case _RecipientChecked() when recipientChecked != null:
|
||||
return recipientChecked();case _Submitted() when submitted != null:
|
||||
return submitted(_that.pin);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( String phone) phoneChanged,required TResult Function( int amount) amountChanged,required TResult Function() recipientChecked,required TResult Function( String pin) submitted,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _CurrencyChanged():
|
||||
return currencyChanged(_that.currency);case _PhoneChanged():
|
||||
return phoneChanged(_that.phone);case _AmountChanged():
|
||||
return amountChanged(_that.amount);case _RecipientChecked():
|
||||
return recipientChecked();case _Submitted():
|
||||
return submitted(_that.pin);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( String phone)? phoneChanged,TResult? Function( int amount)? amountChanged,TResult? Function()? recipientChecked,TResult? Function( String pin)? submitted,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _CurrencyChanged() when currencyChanged != null:
|
||||
return currencyChanged(_that.currency);case _PhoneChanged() when phoneChanged != null:
|
||||
return phoneChanged(_that.phone);case _AmountChanged() when amountChanged != null:
|
||||
return amountChanged(_that.amount);case _RecipientChecked() when recipientChecked != null:
|
||||
return recipientChecked();case _Submitted() when submitted != null:
|
||||
return submitted(_that.pin);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _CurrencyChanged implements TransferFormEvent {
|
||||
const _CurrencyChanged(this.currency);
|
||||
|
||||
|
||||
final WalletCurrency currency;
|
||||
|
||||
/// Create a copy of TransferFormEvent
|
||||
/// 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 'TransferFormEvent.currencyChanged(currency: $currency)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$CurrencyChangedCopyWith<$Res> implements $TransferFormEventCopyWith<$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 TransferFormEvent
|
||||
/// 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 _PhoneChanged implements TransferFormEvent {
|
||||
const _PhoneChanged(this.phone);
|
||||
|
||||
|
||||
final String phone;
|
||||
|
||||
/// Create a copy of TransferFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$PhoneChangedCopyWith<_PhoneChanged> get copyWith => __$PhoneChangedCopyWithImpl<_PhoneChanged>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _PhoneChanged&&(identical(other.phone, phone) || other.phone == phone));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,phone);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TransferFormEvent.phoneChanged(phone: $phone)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$PhoneChangedCopyWith<$Res> implements $TransferFormEventCopyWith<$Res> {
|
||||
factory _$PhoneChangedCopyWith(_PhoneChanged value, $Res Function(_PhoneChanged) _then) = __$PhoneChangedCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String phone
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$PhoneChangedCopyWithImpl<$Res>
|
||||
implements _$PhoneChangedCopyWith<$Res> {
|
||||
__$PhoneChangedCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _PhoneChanged _self;
|
||||
final $Res Function(_PhoneChanged) _then;
|
||||
|
||||
/// Create a copy of TransferFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? phone = null,}) {
|
||||
return _then(_PhoneChanged(
|
||||
null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _AmountChanged implements TransferFormEvent {
|
||||
const _AmountChanged(this.amount);
|
||||
|
||||
|
||||
final int amount;
|
||||
|
||||
/// Create a copy of TransferFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$AmountChangedCopyWith<_AmountChanged> get copyWith => __$AmountChangedCopyWithImpl<_AmountChanged>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _AmountChanged&&(identical(other.amount, amount) || other.amount == amount));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,amount);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TransferFormEvent.amountChanged(amount: $amount)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$AmountChangedCopyWith<$Res> implements $TransferFormEventCopyWith<$Res> {
|
||||
factory _$AmountChangedCopyWith(_AmountChanged value, $Res Function(_AmountChanged) _then) = __$AmountChangedCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
int amount
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$AmountChangedCopyWithImpl<$Res>
|
||||
implements _$AmountChangedCopyWith<$Res> {
|
||||
__$AmountChangedCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _AmountChanged _self;
|
||||
final $Res Function(_AmountChanged) _then;
|
||||
|
||||
/// Create a copy of TransferFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? amount = null,}) {
|
||||
return _then(_AmountChanged(
|
||||
null == amount ? _self.amount : amount // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _RecipientChecked implements TransferFormEvent {
|
||||
const _RecipientChecked();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _RecipientChecked);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TransferFormEvent.recipientChecked()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _Submitted implements TransferFormEvent {
|
||||
const _Submitted(this.pin);
|
||||
|
||||
|
||||
final String pin;
|
||||
|
||||
/// Create a copy of TransferFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$SubmittedCopyWith<_Submitted> get copyWith => __$SubmittedCopyWithImpl<_Submitted>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Submitted&&(identical(other.pin, pin) || other.pin == pin));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,pin);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TransferFormEvent.submitted(pin: $pin)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$SubmittedCopyWith<$Res> implements $TransferFormEventCopyWith<$Res> {
|
||||
factory _$SubmittedCopyWith(_Submitted value, $Res Function(_Submitted) _then) = __$SubmittedCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String pin
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$SubmittedCopyWithImpl<$Res>
|
||||
implements _$SubmittedCopyWith<$Res> {
|
||||
__$SubmittedCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _Submitted _self;
|
||||
final $Res Function(_Submitted) _then;
|
||||
|
||||
/// Create a copy of TransferFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? pin = null,}) {
|
||||
return _then(_Submitted(
|
||||
null == pin ? _self.pin : pin // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$TransferFormState {
|
||||
|
||||
WalletCurrency get currency; String get phone; int get amount; TransferRecipient? get recipient; Option<WalletFailure> get recipientFailureOption; bool get isCheckingRecipient; TransferResult? get result; Option<WalletFailure> get failureOption; bool get isSubmitting; String? get idempotencyKey;
|
||||
/// Create a copy of TransferFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$TransferFormStateCopyWith<TransferFormState> get copyWith => _$TransferFormStateCopyWithImpl<TransferFormState>(this as TransferFormState, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
final _this = this as TransferFormState;
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is TransferFormState&&(identical(other.currency, _this.currency) || other.currency == _this.currency)&&(identical(other.phone, _this.phone) || other.phone == _this.phone)&&(identical(other.amount, _this.amount) || other.amount == _this.amount)&&(identical(other.recipient, _this.recipient) || other.recipient == _this.recipient)&&(identical(other.recipientFailureOption, _this.recipientFailureOption) || other.recipientFailureOption == _this.recipientFailureOption)&&(identical(other.isCheckingRecipient, _this.isCheckingRecipient) || other.isCheckingRecipient == _this.isCheckingRecipient)&&(identical(other.result, _this.result) || other.result == _this.result)&&(identical(other.failureOption, _this.failureOption) || other.failureOption == _this.failureOption)&&(identical(other.isSubmitting, _this.isSubmitting) || other.isSubmitting == _this.isSubmitting)&&(identical(other.idempotencyKey, _this.idempotencyKey) || other.idempotencyKey == _this.idempotencyKey));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as TransferFormState;
|
||||
return Object.hash(runtimeType,_this.currency,_this.phone,_this.amount,_this.recipient,_this.recipientFailureOption,_this.isCheckingRecipient,_this.result,_this.failureOption,_this.isSubmitting,_this.idempotencyKey);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as TransferFormState;
|
||||
return 'TransferFormState(currency: ${_this.currency}, phone: ${_this.phone}, amount: ${_this.amount}, recipient: ${_this.recipient}, recipientFailureOption: ${_this.recipientFailureOption}, isCheckingRecipient: ${_this.isCheckingRecipient}, result: ${_this.result}, failureOption: ${_this.failureOption}, isSubmitting: ${_this.isSubmitting}, idempotencyKey: ${_this.idempotencyKey})';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $TransferFormStateCopyWith<$Res> {
|
||||
factory $TransferFormStateCopyWith(TransferFormState value, $Res Function(TransferFormState) _then) = _$TransferFormStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
WalletCurrency currency, String phone, int amount, TransferRecipient? recipient, Option<WalletFailure> recipientFailureOption, bool isCheckingRecipient, TransferResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey
|
||||
});
|
||||
|
||||
|
||||
$TransferRecipientCopyWith<$Res>? get recipient;$TransferResultCopyWith<$Res>? get result;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$TransferFormStateCopyWithImpl<$Res>
|
||||
implements $TransferFormStateCopyWith<$Res> {
|
||||
_$TransferFormStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final TransferFormState _self;
|
||||
final $Res Function(TransferFormState) _then;
|
||||
|
||||
/// Create a copy of TransferFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? currency = null,Object? phone = null,Object? amount = null,Object? recipient = freezed,Object? recipientFailureOption = null,Object? isCheckingRecipient = null,Object? result = freezed,Object? failureOption = null,Object? isSubmitting = null,Object? idempotencyKey = freezed,}) {
|
||||
return _then(TransferFormState(
|
||||
currency: null == currency ? _self.currency : currency // ignore: cast_nullable_to_non_nullable
|
||||
as WalletCurrency,phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
|
||||
as String,amount: null == amount ? _self.amount : amount // ignore: cast_nullable_to_non_nullable
|
||||
as int,recipient: freezed == recipient ? _self.recipient : recipient // ignore: cast_nullable_to_non_nullable
|
||||
as TransferRecipient?,recipientFailureOption: null == recipientFailureOption ? _self.recipientFailureOption : recipientFailureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,isCheckingRecipient: null == isCheckingRecipient ? _self.isCheckingRecipient : isCheckingRecipient // ignore: cast_nullable_to_non_nullable
|
||||
as bool,result: freezed == result ? _self.result : result // ignore: cast_nullable_to_non_nullable
|
||||
as TransferResult?,failureOption: null == failureOption ? _self.failureOption : failureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,isSubmitting: null == isSubmitting ? _self.isSubmitting : isSubmitting // ignore: cast_nullable_to_non_nullable
|
||||
as bool,idempotencyKey: freezed == idempotencyKey ? _self.idempotencyKey : idempotencyKey // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
));
|
||||
}
|
||||
/// Create a copy of TransferFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$TransferRecipientCopyWith<$Res>? get recipient {
|
||||
if (_self.recipient == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $TransferRecipientCopyWith<$Res>(_self.recipient!, (value) {
|
||||
return _then(_self.copyWith(recipient: value));
|
||||
});
|
||||
}/// Create a copy of TransferFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$TransferResultCopyWith<$Res>? get result {
|
||||
if (_self.result == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $TransferResultCopyWith<$Res>(_self.result!, (value) {
|
||||
return _then(_self.copyWith(result: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [TransferFormState].
|
||||
extension TransferFormStatePatterns on TransferFormState {
|
||||
/// 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( _TransferFormState value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _TransferFormState() 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( _TransferFormState value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _TransferFormState():
|
||||
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( _TransferFormState value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _TransferFormState() 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, String phone, int amount, TransferRecipient? recipient, Option<WalletFailure> recipientFailureOption, bool isCheckingRecipient, TransferResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _TransferFormState() when $default != null:
|
||||
return $default(_that.currency,_that.phone,_that.amount,_that.recipient,_that.recipientFailureOption,_that.isCheckingRecipient,_that.result,_that.failureOption,_that.isSubmitting,_that.idempotencyKey);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, String phone, int amount, TransferRecipient? recipient, Option<WalletFailure> recipientFailureOption, bool isCheckingRecipient, TransferResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _TransferFormState():
|
||||
return $default(_that.currency,_that.phone,_that.amount,_that.recipient,_that.recipientFailureOption,_that.isCheckingRecipient,_that.result,_that.failureOption,_that.isSubmitting,_that.idempotencyKey);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, String phone, int amount, TransferRecipient? recipient, Option<WalletFailure> recipientFailureOption, bool isCheckingRecipient, TransferResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _TransferFormState() when $default != null:
|
||||
return $default(_that.currency,_that.phone,_that.amount,_that.recipient,_that.recipientFailureOption,_that.isCheckingRecipient,_that.result,_that.failureOption,_that.isSubmitting,_that.idempotencyKey);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _TransferFormState extends TransferFormState {
|
||||
const _TransferFormState({required this.currency, required this.phone, required this.amount, this.recipient, required this.recipientFailureOption, this.isCheckingRecipient = false, this.result, required this.failureOption, this.isSubmitting = false, this.idempotencyKey}): super._();
|
||||
|
||||
|
||||
@override final WalletCurrency currency;
|
||||
@override final String phone;
|
||||
@override final int amount;
|
||||
@override final TransferRecipient? recipient;
|
||||
@override final Option<WalletFailure> recipientFailureOption;
|
||||
@override@JsonKey() final bool isCheckingRecipient;
|
||||
@override final TransferResult? result;
|
||||
@override final Option<WalletFailure> failureOption;
|
||||
@override@JsonKey() final bool isSubmitting;
|
||||
@override final String? idempotencyKey;
|
||||
|
||||
/// Create a copy of TransferFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$TransferFormStateCopyWith<_TransferFormState> get copyWith => __$TransferFormStateCopyWithImpl<_TransferFormState>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _TransferFormState&&(identical(other.currency, currency) || other.currency == currency)&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.amount, amount) || other.amount == amount)&&(identical(other.recipient, recipient) || other.recipient == recipient)&&(identical(other.recipientFailureOption, recipientFailureOption) || other.recipientFailureOption == recipientFailureOption)&&(identical(other.isCheckingRecipient, isCheckingRecipient) || other.isCheckingRecipient == isCheckingRecipient)&&(identical(other.result, result) || other.result == result)&&(identical(other.failureOption, failureOption) || other.failureOption == failureOption)&&(identical(other.isSubmitting, isSubmitting) || other.isSubmitting == isSubmitting)&&(identical(other.idempotencyKey, idempotencyKey) || other.idempotencyKey == idempotencyKey));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,currency,phone,amount,recipient,recipientFailureOption,isCheckingRecipient,result,failureOption,isSubmitting,idempotencyKey);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TransferFormState(currency: $currency, phone: $phone, amount: $amount, recipient: $recipient, recipientFailureOption: $recipientFailureOption, isCheckingRecipient: $isCheckingRecipient, result: $result, failureOption: $failureOption, isSubmitting: $isSubmitting, idempotencyKey: $idempotencyKey)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$TransferFormStateCopyWith<$Res> implements $TransferFormStateCopyWith<$Res> {
|
||||
factory _$TransferFormStateCopyWith(_TransferFormState value, $Res Function(_TransferFormState) _then) = __$TransferFormStateCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
WalletCurrency currency, String phone, int amount, TransferRecipient? recipient, Option<WalletFailure> recipientFailureOption, bool isCheckingRecipient, TransferResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey
|
||||
});
|
||||
|
||||
|
||||
@override $TransferRecipientCopyWith<$Res>? get recipient;@override $TransferResultCopyWith<$Res>? get result;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$TransferFormStateCopyWithImpl<$Res>
|
||||
implements _$TransferFormStateCopyWith<$Res> {
|
||||
__$TransferFormStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _TransferFormState _self;
|
||||
final $Res Function(_TransferFormState) _then;
|
||||
|
||||
/// Create a copy of TransferFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? currency = null,Object? phone = null,Object? amount = null,Object? recipient = freezed,Object? recipientFailureOption = null,Object? isCheckingRecipient = null,Object? result = freezed,Object? failureOption = null,Object? isSubmitting = null,Object? idempotencyKey = freezed,}) {
|
||||
return _then(_TransferFormState(
|
||||
currency: null == currency ? _self.currency : currency // ignore: cast_nullable_to_non_nullable
|
||||
as WalletCurrency,phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
|
||||
as String,amount: null == amount ? _self.amount : amount // ignore: cast_nullable_to_non_nullable
|
||||
as int,recipient: freezed == recipient ? _self.recipient : recipient // ignore: cast_nullable_to_non_nullable
|
||||
as TransferRecipient?,recipientFailureOption: null == recipientFailureOption ? _self.recipientFailureOption : recipientFailureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,isCheckingRecipient: null == isCheckingRecipient ? _self.isCheckingRecipient : isCheckingRecipient // ignore: cast_nullable_to_non_nullable
|
||||
as bool,result: freezed == result ? _self.result : result // ignore: cast_nullable_to_non_nullable
|
||||
as TransferResult?,failureOption: null == failureOption ? _self.failureOption : failureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,isSubmitting: null == isSubmitting ? _self.isSubmitting : isSubmitting // ignore: cast_nullable_to_non_nullable
|
||||
as bool,idempotencyKey: freezed == idempotencyKey ? _self.idempotencyKey : idempotencyKey // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
));
|
||||
}
|
||||
|
||||
/// Create a copy of TransferFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$TransferRecipientCopyWith<$Res>? get recipient {
|
||||
if (_self.recipient == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $TransferRecipientCopyWith<$Res>(_self.recipient!, (value) {
|
||||
return _then(_self.copyWith(recipient: value));
|
||||
});
|
||||
}/// Create a copy of TransferFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$TransferResultCopyWith<$Res>? get result {
|
||||
if (_self.result == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $TransferResultCopyWith<$Res>(_self.result!, (value) {
|
||||
return _then(_self.copyWith(result: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -0,0 +1,16 @@
|
||||
part of 'transfer_form_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class TransferFormEvent with _$TransferFormEvent {
|
||||
const factory TransferFormEvent.currencyChanged(WalletCurrency currency) =
|
||||
_CurrencyChanged;
|
||||
|
||||
const factory TransferFormEvent.phoneChanged(String phone) = _PhoneChanged;
|
||||
|
||||
const factory TransferFormEvent.amountChanged(int amount) = _AmountChanged;
|
||||
|
||||
const factory TransferFormEvent.recipientChecked() = _RecipientChecked;
|
||||
|
||||
/// [pin] hanya diteruskan ke API, tidak disimpan di state.
|
||||
const factory TransferFormEvent.submitted(String pin) = _Submitted;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
part of 'transfer_form_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class TransferFormState with _$TransferFormState {
|
||||
const TransferFormState._();
|
||||
|
||||
const factory TransferFormState({
|
||||
required WalletCurrency currency,
|
||||
required String phone,
|
||||
required int amount,
|
||||
TransferRecipient? recipient,
|
||||
required Option<WalletFailure> recipientFailureOption,
|
||||
@Default(false) bool isCheckingRecipient,
|
||||
TransferResult? result,
|
||||
required Option<WalletFailure> failureOption,
|
||||
@Default(false) bool isSubmitting,
|
||||
String? idempotencyKey,
|
||||
}) = _TransferFormState;
|
||||
|
||||
factory TransferFormState.initial() => TransferFormState(
|
||||
currency: WalletCurrency.point,
|
||||
phone: '',
|
||||
amount: 0,
|
||||
recipientFailureOption: none(),
|
||||
failureOption: none(),
|
||||
);
|
||||
|
||||
bool get isFilled => phone.length >= 9 && amount > 0;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
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_expiring_loader_event.dart';
|
||||
part 'wallet_expiring_loader_state.dart';
|
||||
part 'wallet_expiring_loader_bloc.freezed.dart';
|
||||
|
||||
@injectable
|
||||
class WalletExpiringLoaderBloc
|
||||
extends Bloc<WalletExpiringLoaderEvent, WalletExpiringLoaderState> {
|
||||
final IWalletRepository _repository;
|
||||
|
||||
WalletExpiringLoaderBloc(this._repository)
|
||||
: super(WalletExpiringLoaderState.initial()) {
|
||||
on<WalletExpiringLoaderEvent>(_onWalletExpiringLoaderEvent);
|
||||
}
|
||||
|
||||
Future<void> _onWalletExpiringLoaderEvent(
|
||||
WalletExpiringLoaderEvent event,
|
||||
Emitter<WalletExpiringLoaderState> emit,
|
||||
) {
|
||||
return event.map(
|
||||
fetched: (e) async {
|
||||
emit(state.copyWith(isFetching: true, failureOption: none()));
|
||||
|
||||
final result = await _repository.getExpiring();
|
||||
|
||||
final data = result.fold(
|
||||
(f) => state.copyWith(failureOption: optionOf(f)),
|
||||
(expiring) => state.copyWith(expiring: expiring),
|
||||
);
|
||||
|
||||
emit(data.copyWith(isFetching: false));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
+495
@@ -0,0 +1,495 @@
|
||||
// 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_expiring_loader_bloc.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$WalletExpiringLoaderEvent {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is WalletExpiringLoaderEvent);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletExpiringLoaderEvent()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class $WalletExpiringLoaderEventCopyWith<$Res> {
|
||||
$WalletExpiringLoaderEventCopyWith(WalletExpiringLoaderEvent _, $Res Function(WalletExpiringLoaderEvent) __);
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [WalletExpiringLoaderEvent].
|
||||
extension WalletExpiringLoaderEventPatterns on WalletExpiringLoaderEvent {
|
||||
/// 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( _Fetched value)? fetched,required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _Fetched() when fetched != null:
|
||||
return fetched(_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( _Fetched value) fetched,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _Fetched():
|
||||
return fetched(_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( _Fetched value)? fetched,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _Fetched() when fetched != null:
|
||||
return fetched(_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()? fetched,required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _Fetched() when fetched != null:
|
||||
return fetched();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() fetched,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _Fetched():
|
||||
return fetched();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()? fetched,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _Fetched() when fetched != null:
|
||||
return fetched();case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _Fetched implements WalletExpiringLoaderEvent {
|
||||
const _Fetched();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Fetched);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletExpiringLoaderEvent.fetched()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// @nodoc
|
||||
mixin _$WalletExpiringLoaderState {
|
||||
|
||||
WalletExpiring get expiring; Option<WalletFailure> get failureOption; bool get isFetching;
|
||||
/// Create a copy of WalletExpiringLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$WalletExpiringLoaderStateCopyWith<WalletExpiringLoaderState> get copyWith => _$WalletExpiringLoaderStateCopyWithImpl<WalletExpiringLoaderState>(this as WalletExpiringLoaderState, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
final _this = this as WalletExpiringLoaderState;
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is WalletExpiringLoaderState&&(identical(other.expiring, _this.expiring) || other.expiring == _this.expiring)&&(identical(other.failureOption, _this.failureOption) || other.failureOption == _this.failureOption)&&(identical(other.isFetching, _this.isFetching) || other.isFetching == _this.isFetching));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as WalletExpiringLoaderState;
|
||||
return Object.hash(runtimeType,_this.expiring,_this.failureOption,_this.isFetching);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as WalletExpiringLoaderState;
|
||||
return 'WalletExpiringLoaderState(expiring: ${_this.expiring}, failureOption: ${_this.failureOption}, isFetching: ${_this.isFetching})';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $WalletExpiringLoaderStateCopyWith<$Res> {
|
||||
factory $WalletExpiringLoaderStateCopyWith(WalletExpiringLoaderState value, $Res Function(WalletExpiringLoaderState) _then) = _$WalletExpiringLoaderStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
WalletExpiring expiring, Option<WalletFailure> failureOption, bool isFetching
|
||||
});
|
||||
|
||||
|
||||
$WalletExpiringCopyWith<$Res> get expiring;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$WalletExpiringLoaderStateCopyWithImpl<$Res>
|
||||
implements $WalletExpiringLoaderStateCopyWith<$Res> {
|
||||
_$WalletExpiringLoaderStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final WalletExpiringLoaderState _self;
|
||||
final $Res Function(WalletExpiringLoaderState) _then;
|
||||
|
||||
/// Create a copy of WalletExpiringLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? expiring = null,Object? failureOption = null,Object? isFetching = null,}) {
|
||||
return _then(WalletExpiringLoaderState(
|
||||
expiring: null == expiring ? _self.expiring : expiring // ignore: cast_nullable_to_non_nullable
|
||||
as WalletExpiring,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,
|
||||
));
|
||||
}
|
||||
/// Create a copy of WalletExpiringLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$WalletExpiringCopyWith<$Res> get expiring {
|
||||
|
||||
return $WalletExpiringCopyWith<$Res>(_self.expiring, (value) {
|
||||
return _then(_self.copyWith(expiring: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [WalletExpiringLoaderState].
|
||||
extension WalletExpiringLoaderStatePatterns on WalletExpiringLoaderState {
|
||||
/// 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( _WalletExpiringLoaderState value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletExpiringLoaderState() 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( _WalletExpiringLoaderState value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletExpiringLoaderState():
|
||||
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( _WalletExpiringLoaderState value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletExpiringLoaderState() 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( WalletExpiring expiring, Option<WalletFailure> failureOption, bool isFetching)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletExpiringLoaderState() when $default != null:
|
||||
return $default(_that.expiring,_that.failureOption,_that.isFetching);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( WalletExpiring expiring, Option<WalletFailure> failureOption, bool isFetching) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletExpiringLoaderState():
|
||||
return $default(_that.expiring,_that.failureOption,_that.isFetching);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( WalletExpiring expiring, Option<WalletFailure> failureOption, bool isFetching)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletExpiringLoaderState() when $default != null:
|
||||
return $default(_that.expiring,_that.failureOption,_that.isFetching);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _WalletExpiringLoaderState implements WalletExpiringLoaderState {
|
||||
const _WalletExpiringLoaderState({required this.expiring, required this.failureOption, this.isFetching = false});
|
||||
|
||||
|
||||
@override final WalletExpiring expiring;
|
||||
@override final Option<WalletFailure> failureOption;
|
||||
@override@JsonKey() final bool isFetching;
|
||||
|
||||
/// Create a copy of WalletExpiringLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$WalletExpiringLoaderStateCopyWith<_WalletExpiringLoaderState> get copyWith => __$WalletExpiringLoaderStateCopyWithImpl<_WalletExpiringLoaderState>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _WalletExpiringLoaderState&&(identical(other.expiring, expiring) || other.expiring == expiring)&&(identical(other.failureOption, failureOption) || other.failureOption == failureOption)&&(identical(other.isFetching, isFetching) || other.isFetching == isFetching));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,expiring,failureOption,isFetching);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletExpiringLoaderState(expiring: $expiring, failureOption: $failureOption, isFetching: $isFetching)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$WalletExpiringLoaderStateCopyWith<$Res> implements $WalletExpiringLoaderStateCopyWith<$Res> {
|
||||
factory _$WalletExpiringLoaderStateCopyWith(_WalletExpiringLoaderState value, $Res Function(_WalletExpiringLoaderState) _then) = __$WalletExpiringLoaderStateCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
WalletExpiring expiring, Option<WalletFailure> failureOption, bool isFetching
|
||||
});
|
||||
|
||||
|
||||
@override $WalletExpiringCopyWith<$Res> get expiring;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$WalletExpiringLoaderStateCopyWithImpl<$Res>
|
||||
implements _$WalletExpiringLoaderStateCopyWith<$Res> {
|
||||
__$WalletExpiringLoaderStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _WalletExpiringLoaderState _self;
|
||||
final $Res Function(_WalletExpiringLoaderState) _then;
|
||||
|
||||
/// Create a copy of WalletExpiringLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? expiring = null,Object? failureOption = null,Object? isFetching = null,}) {
|
||||
return _then(_WalletExpiringLoaderState(
|
||||
expiring: null == expiring ? _self.expiring : expiring // ignore: cast_nullable_to_non_nullable
|
||||
as WalletExpiring,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,
|
||||
));
|
||||
}
|
||||
|
||||
/// Create a copy of WalletExpiringLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$WalletExpiringCopyWith<$Res> get expiring {
|
||||
|
||||
return $WalletExpiringCopyWith<$Res>(_self.expiring, (value) {
|
||||
return _then(_self.copyWith(expiring: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -0,0 +1,6 @@
|
||||
part of 'wallet_expiring_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class WalletExpiringLoaderEvent with _$WalletExpiringLoaderEvent {
|
||||
const factory WalletExpiringLoaderEvent.fetched() = _Fetched;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
part of 'wallet_expiring_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class WalletExpiringLoaderState with _$WalletExpiringLoaderState {
|
||||
const factory WalletExpiringLoaderState({
|
||||
required WalletExpiring expiring,
|
||||
required Option<WalletFailure> failureOption,
|
||||
@Default(false) bool isFetching,
|
||||
}) = _WalletExpiringLoaderState;
|
||||
|
||||
factory WalletExpiringLoaderState.initial() => WalletExpiringLoaderState(
|
||||
expiring: WalletExpiring.empty(),
|
||||
failureOption: none(),
|
||||
);
|
||||
}
|
||||
@@ -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';
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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_loader_event.dart';
|
||||
part 'wallet_loader_state.dart';
|
||||
part 'wallet_loader_bloc.freezed.dart';
|
||||
|
||||
@injectable
|
||||
class WalletLoaderBloc extends Bloc<WalletLoaderEvent, WalletLoaderState> {
|
||||
final IWalletRepository _repository;
|
||||
|
||||
WalletLoaderBloc(this._repository) : super(WalletLoaderState.initial()) {
|
||||
on<WalletLoaderEvent>(_onWalletLoaderEvent);
|
||||
}
|
||||
|
||||
Future<void> _onWalletLoaderEvent(
|
||||
WalletLoaderEvent event,
|
||||
Emitter<WalletLoaderState> emit,
|
||||
) {
|
||||
return event.map(
|
||||
fetched: (e) async {
|
||||
emit(state.copyWith(isFetching: true, failureOption: none()));
|
||||
|
||||
final result = await _repository.getWallet();
|
||||
|
||||
final data = result.fold(
|
||||
(f) => state.copyWith(failureOption: optionOf(f)),
|
||||
(summary) => state.copyWith(summary: summary, hasLoaded: true),
|
||||
);
|
||||
|
||||
emit(data.copyWith(isFetching: false));
|
||||
},
|
||||
coinBalanceUpdated: (e) async {
|
||||
emit(
|
||||
state.copyWith(
|
||||
summary: state.summary.copyWith(coinBalance: e.coinBalance),
|
||||
),
|
||||
);
|
||||
},
|
||||
cleared: (e) async => emit(WalletLoaderState.initial()),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,610 @@
|
||||
// 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_loader_bloc.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$WalletLoaderEvent {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is WalletLoaderEvent);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletLoaderEvent()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class $WalletLoaderEventCopyWith<$Res> {
|
||||
$WalletLoaderEventCopyWith(WalletLoaderEvent _, $Res Function(WalletLoaderEvent) __);
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [WalletLoaderEvent].
|
||||
extension WalletLoaderEventPatterns on WalletLoaderEvent {
|
||||
/// 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( _Fetched value)? fetched,TResult Function( _CoinBalanceUpdated value)? coinBalanceUpdated,TResult Function( _Cleared value)? cleared,required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _Fetched() when fetched != null:
|
||||
return fetched(_that);case _CoinBalanceUpdated() when coinBalanceUpdated != null:
|
||||
return coinBalanceUpdated(_that);case _Cleared() when cleared != null:
|
||||
return cleared(_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( _Fetched value) fetched,required TResult Function( _CoinBalanceUpdated value) coinBalanceUpdated,required TResult Function( _Cleared value) cleared,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _Fetched():
|
||||
return fetched(_that);case _CoinBalanceUpdated():
|
||||
return coinBalanceUpdated(_that);case _Cleared():
|
||||
return cleared(_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( _Fetched value)? fetched,TResult? Function( _CoinBalanceUpdated value)? coinBalanceUpdated,TResult? Function( _Cleared value)? cleared,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _Fetched() when fetched != null:
|
||||
return fetched(_that);case _CoinBalanceUpdated() when coinBalanceUpdated != null:
|
||||
return coinBalanceUpdated(_that);case _Cleared() when cleared != null:
|
||||
return cleared(_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()? fetched,TResult Function( int coinBalance)? coinBalanceUpdated,TResult Function()? cleared,required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _Fetched() when fetched != null:
|
||||
return fetched();case _CoinBalanceUpdated() when coinBalanceUpdated != null:
|
||||
return coinBalanceUpdated(_that.coinBalance);case _Cleared() when cleared != null:
|
||||
return cleared();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() fetched,required TResult Function( int coinBalance) coinBalanceUpdated,required TResult Function() cleared,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _Fetched():
|
||||
return fetched();case _CoinBalanceUpdated():
|
||||
return coinBalanceUpdated(_that.coinBalance);case _Cleared():
|
||||
return cleared();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()? fetched,TResult? Function( int coinBalance)? coinBalanceUpdated,TResult? Function()? cleared,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _Fetched() when fetched != null:
|
||||
return fetched();case _CoinBalanceUpdated() when coinBalanceUpdated != null:
|
||||
return coinBalanceUpdated(_that.coinBalance);case _Cleared() when cleared != null:
|
||||
return cleared();case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _Fetched implements WalletLoaderEvent {
|
||||
const _Fetched();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Fetched);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletLoaderEvent.fetched()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _CoinBalanceUpdated implements WalletLoaderEvent {
|
||||
const _CoinBalanceUpdated(this.coinBalance);
|
||||
|
||||
|
||||
final int coinBalance;
|
||||
|
||||
/// Create a copy of WalletLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$CoinBalanceUpdatedCopyWith<_CoinBalanceUpdated> get copyWith => __$CoinBalanceUpdatedCopyWithImpl<_CoinBalanceUpdated>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _CoinBalanceUpdated&&(identical(other.coinBalance, coinBalance) || other.coinBalance == coinBalance));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,coinBalance);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletLoaderEvent.coinBalanceUpdated(coinBalance: $coinBalance)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$CoinBalanceUpdatedCopyWith<$Res> implements $WalletLoaderEventCopyWith<$Res> {
|
||||
factory _$CoinBalanceUpdatedCopyWith(_CoinBalanceUpdated value, $Res Function(_CoinBalanceUpdated) _then) = __$CoinBalanceUpdatedCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
int coinBalance
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$CoinBalanceUpdatedCopyWithImpl<$Res>
|
||||
implements _$CoinBalanceUpdatedCopyWith<$Res> {
|
||||
__$CoinBalanceUpdatedCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _CoinBalanceUpdated _self;
|
||||
final $Res Function(_CoinBalanceUpdated) _then;
|
||||
|
||||
/// Create a copy of WalletLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? coinBalance = null,}) {
|
||||
return _then(_CoinBalanceUpdated(
|
||||
null == coinBalance ? _self.coinBalance : coinBalance // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _Cleared implements WalletLoaderEvent {
|
||||
const _Cleared();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Cleared);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletLoaderEvent.cleared()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// @nodoc
|
||||
mixin _$WalletLoaderState {
|
||||
|
||||
WalletSummary get summary; Option<WalletFailure> get failureOption; bool get isFetching; bool get hasLoaded;
|
||||
/// Create a copy of WalletLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$WalletLoaderStateCopyWith<WalletLoaderState> get copyWith => _$WalletLoaderStateCopyWithImpl<WalletLoaderState>(this as WalletLoaderState, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
final _this = this as WalletLoaderState;
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is WalletLoaderState&&(identical(other.summary, _this.summary) || other.summary == _this.summary)&&(identical(other.failureOption, _this.failureOption) || other.failureOption == _this.failureOption)&&(identical(other.isFetching, _this.isFetching) || other.isFetching == _this.isFetching)&&(identical(other.hasLoaded, _this.hasLoaded) || other.hasLoaded == _this.hasLoaded));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as WalletLoaderState;
|
||||
return Object.hash(runtimeType,_this.summary,_this.failureOption,_this.isFetching,_this.hasLoaded);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as WalletLoaderState;
|
||||
return 'WalletLoaderState(summary: ${_this.summary}, failureOption: ${_this.failureOption}, isFetching: ${_this.isFetching}, hasLoaded: ${_this.hasLoaded})';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $WalletLoaderStateCopyWith<$Res> {
|
||||
factory $WalletLoaderStateCopyWith(WalletLoaderState value, $Res Function(WalletLoaderState) _then) = _$WalletLoaderStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
WalletSummary summary, Option<WalletFailure> failureOption, bool isFetching, bool hasLoaded
|
||||
});
|
||||
|
||||
|
||||
$WalletSummaryCopyWith<$Res> get summary;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$WalletLoaderStateCopyWithImpl<$Res>
|
||||
implements $WalletLoaderStateCopyWith<$Res> {
|
||||
_$WalletLoaderStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final WalletLoaderState _self;
|
||||
final $Res Function(WalletLoaderState) _then;
|
||||
|
||||
/// Create a copy of WalletLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? summary = null,Object? failureOption = null,Object? isFetching = null,Object? hasLoaded = null,}) {
|
||||
return _then(WalletLoaderState(
|
||||
summary: null == summary ? _self.summary : summary // ignore: cast_nullable_to_non_nullable
|
||||
as WalletSummary,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,hasLoaded: null == hasLoaded ? _self.hasLoaded : hasLoaded // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
/// Create a copy of WalletLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$WalletSummaryCopyWith<$Res> get summary {
|
||||
|
||||
return $WalletSummaryCopyWith<$Res>(_self.summary, (value) {
|
||||
return _then(_self.copyWith(summary: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [WalletLoaderState].
|
||||
extension WalletLoaderStatePatterns on WalletLoaderState {
|
||||
/// 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( _WalletLoaderState value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletLoaderState() 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( _WalletLoaderState value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletLoaderState():
|
||||
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( _WalletLoaderState value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletLoaderState() 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( WalletSummary summary, Option<WalletFailure> failureOption, bool isFetching, bool hasLoaded)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletLoaderState() when $default != null:
|
||||
return $default(_that.summary,_that.failureOption,_that.isFetching,_that.hasLoaded);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( WalletSummary summary, Option<WalletFailure> failureOption, bool isFetching, bool hasLoaded) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletLoaderState():
|
||||
return $default(_that.summary,_that.failureOption,_that.isFetching,_that.hasLoaded);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( WalletSummary summary, Option<WalletFailure> failureOption, bool isFetching, bool hasLoaded)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _WalletLoaderState() when $default != null:
|
||||
return $default(_that.summary,_that.failureOption,_that.isFetching,_that.hasLoaded);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _WalletLoaderState implements WalletLoaderState {
|
||||
const _WalletLoaderState({required this.summary, required this.failureOption, this.isFetching = false, this.hasLoaded = false});
|
||||
|
||||
|
||||
@override final WalletSummary summary;
|
||||
@override final Option<WalletFailure> failureOption;
|
||||
@override@JsonKey() final bool isFetching;
|
||||
@override@JsonKey() final bool hasLoaded;
|
||||
|
||||
/// Create a copy of WalletLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$WalletLoaderStateCopyWith<_WalletLoaderState> get copyWith => __$WalletLoaderStateCopyWithImpl<_WalletLoaderState>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _WalletLoaderState&&(identical(other.summary, summary) || other.summary == summary)&&(identical(other.failureOption, failureOption) || other.failureOption == failureOption)&&(identical(other.isFetching, isFetching) || other.isFetching == isFetching)&&(identical(other.hasLoaded, hasLoaded) || other.hasLoaded == hasLoaded));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,summary,failureOption,isFetching,hasLoaded);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WalletLoaderState(summary: $summary, failureOption: $failureOption, isFetching: $isFetching, hasLoaded: $hasLoaded)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$WalletLoaderStateCopyWith<$Res> implements $WalletLoaderStateCopyWith<$Res> {
|
||||
factory _$WalletLoaderStateCopyWith(_WalletLoaderState value, $Res Function(_WalletLoaderState) _then) = __$WalletLoaderStateCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
WalletSummary summary, Option<WalletFailure> failureOption, bool isFetching, bool hasLoaded
|
||||
});
|
||||
|
||||
|
||||
@override $WalletSummaryCopyWith<$Res> get summary;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$WalletLoaderStateCopyWithImpl<$Res>
|
||||
implements _$WalletLoaderStateCopyWith<$Res> {
|
||||
__$WalletLoaderStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _WalletLoaderState _self;
|
||||
final $Res Function(_WalletLoaderState) _then;
|
||||
|
||||
/// Create a copy of WalletLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? summary = null,Object? failureOption = null,Object? isFetching = null,Object? hasLoaded = null,}) {
|
||||
return _then(_WalletLoaderState(
|
||||
summary: null == summary ? _self.summary : summary // ignore: cast_nullable_to_non_nullable
|
||||
as WalletSummary,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,hasLoaded: null == hasLoaded ? _self.hasLoaded : hasLoaded // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
|
||||
/// Create a copy of WalletLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$WalletSummaryCopyWith<$Res> get summary {
|
||||
|
||||
return $WalletSummaryCopyWith<$Res>(_self.summary, (value) {
|
||||
return _then(_self.copyWith(summary: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -0,0 +1,13 @@
|
||||
part of 'wallet_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class WalletLoaderEvent with _$WalletLoaderEvent {
|
||||
const factory WalletLoaderEvent.fetched() = _Fetched;
|
||||
|
||||
/// Saldo EnakCoin terbaru dari hasil main game (`coins_remaining`).
|
||||
const factory WalletLoaderEvent.coinBalanceUpdated(int coinBalance) =
|
||||
_CoinBalanceUpdated;
|
||||
|
||||
/// Dipanggil saat logout supaya saldo akun sebelumnya tidak tertampil.
|
||||
const factory WalletLoaderEvent.cleared() = _Cleared;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
part of 'wallet_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class WalletLoaderState with _$WalletLoaderState {
|
||||
const factory WalletLoaderState({
|
||||
required WalletSummary summary,
|
||||
required Option<WalletFailure> failureOption,
|
||||
@Default(false) bool isFetching,
|
||||
@Default(false) bool hasLoaded,
|
||||
}) = _WalletLoaderState;
|
||||
|
||||
factory WalletLoaderState.initial() =>
|
||||
WalletLoaderState(summary: WalletSummary.empty(), failureOption: none());
|
||||
}
|
||||
Reference in New Issue
Block a user