feat: integrate enakgame and voucher
Build & Deploy iOS to TestFlight / build-and-deploy (push) Canceled after 0s

This commit is contained in:
efrilm
2026-10-10 02:33:16 +07:00
parent e5515d5871
commit 38850b281f
104 changed files with 7122 additions and 8063 deletions
@@ -1,42 +0,0 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/game/game.dart';
part 'ferris_wheel_loader_event.dart';
part 'ferris_wheel_loader_state.dart';
part 'ferris_wheel_loader_bloc.freezed.dart';
@injectable
class FerrisWheelLoaderBloc
extends Bloc<FerrisWheelLoaderEvent, FerrisWheelLoaderState> {
final IGameRepository _repository;
FerrisWheelLoaderBloc(this._repository)
: super(FerrisWheelLoaderState.initial()) {
on<FerrisWheelLoaderEvent>(_onFerrisWheelLoaderEvent);
}
Future<void> _onFerrisWheelLoaderEvent(
FerrisWheelLoaderEvent event,
Emitter<FerrisWheelLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(
state.copyWith(isFetching: true, failureOptionFerrisWheel: none()),
);
final result = await _repository.ferrisWheel();
var data = result.fold(
(f) => state.copyWith(failureOptionFerrisWheel: optionOf(f)),
(ferrisWheel) => state.copyWith(ferrisWheel: ferrisWheel),
);
emit(data.copyWith(isFetching: false));
},
);
}
}
@@ -1,6 +0,0 @@
part of 'ferris_wheel_loader_bloc.dart';
@freezed
abstract class FerrisWheelLoaderEvent with _$FerrisWheelLoaderEvent {
const factory FerrisWheelLoaderEvent.fetched() = _Fetched;
}
@@ -1,15 +0,0 @@
part of 'ferris_wheel_loader_bloc.dart';
@freezed
abstract class FerrisWheelLoaderState with _$FerrisWheelLoaderState {
const factory FerrisWheelLoaderState({
required Game ferrisWheel,
required Option<GameFailure> failureOptionFerrisWheel,
@Default(false) bool isFetching,
}) = _FerrisWheelLoaderState;
factory FerrisWheelLoaderState.initial() => FerrisWheelLoaderState(
ferrisWheel: Game.empty(),
failureOptionFerrisWheel: none(),
);
}
@@ -1,40 +0,0 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/game/game.dart';
part 'game_spin_event.dart';
part 'game_spin_state.dart';
part 'game_spin_bloc.freezed.dart';
@injectable
class GameSpinBloc extends Bloc<GameSpinEvent, GameSpinState> {
final IGameRepository _repository;
GameSpinBloc(this._repository) : super(GameSpinState.initial()) {
on<GameSpinEvent>(_onGameSpinEvent);
}
Future<void> _onGameSpinEvent(
GameSpinEvent event,
Emitter<GameSpinState> emit,
) {
return event.map(
spun: (e) async {
if (state.isSpinning) return;
emit(state.copyWith(isSpinning: true, failureOrResultOption: none()));
final result = await _repository.spin(gameId: e.gameId);
emit(
state.copyWith(
isSpinning: false,
failureOrResultOption: optionOf(result),
),
);
},
);
}
}
@@ -1,546 +0,0 @@
// 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 'game_spin_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$GameSpinEvent {
String get gameId;
/// Create a copy of GameSpinEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$GameSpinEventCopyWith<GameSpinEvent> get copyWith => _$GameSpinEventCopyWithImpl<GameSpinEvent>(this as GameSpinEvent, _$identity);
@override
bool operator ==(Object other) {
final _this = this as GameSpinEvent;
return identical(this, other) || (other.runtimeType == runtimeType&&other is GameSpinEvent&&(identical(other.gameId, _this.gameId) || other.gameId == _this.gameId));
}
@override
int get hashCode {
final _this = this as GameSpinEvent;
return Object.hash(runtimeType,_this.gameId);
}
@override
String toString() {
final _this = this as GameSpinEvent;
return 'GameSpinEvent(gameId: ${_this.gameId})';
}
}
/// @nodoc
abstract mixin class $GameSpinEventCopyWith<$Res> {
factory $GameSpinEventCopyWith(GameSpinEvent value, $Res Function(GameSpinEvent) _then) = _$GameSpinEventCopyWithImpl;
@useResult
$Res call({
String gameId
});
}
/// @nodoc
class _$GameSpinEventCopyWithImpl<$Res>
implements $GameSpinEventCopyWith<$Res> {
_$GameSpinEventCopyWithImpl(this._self, this._then);
final GameSpinEvent _self;
final $Res Function(GameSpinEvent) _then;
/// Create a copy of GameSpinEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? gameId = null,}) {
return _then(GameSpinEvent.spun(
null == gameId ? _self.gameId : gameId // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [GameSpinEvent].
extension GameSpinEventPatterns on GameSpinEvent {
/// 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( _Spun value)? spun,required TResult orElse(),}){
final _that = this;
switch (_that) {
case _Spun() when spun != null:
return spun(_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( _Spun value) spun,}){
final _that = this;
switch (_that) {
case _Spun():
return spun(_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( _Spun value)? spun,}){
final _that = this;
switch (_that) {
case _Spun() when spun != null:
return spun(_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 gameId)? spun,required TResult orElse(),}) {final _that = this;
switch (_that) {
case _Spun() when spun != null:
return spun(_that.gameId);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 gameId) spun,}) {final _that = this;
switch (_that) {
case _Spun():
return spun(_that.gameId);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 gameId)? spun,}) {final _that = this;
switch (_that) {
case _Spun() when spun != null:
return spun(_that.gameId);case _:
return null;
}
}
}
/// @nodoc
class _Spun implements GameSpinEvent {
const _Spun(this.gameId);
@override final String gameId;
/// Create a copy of GameSpinEvent
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$SpunCopyWith<_Spun> get copyWith => __$SpunCopyWithImpl<_Spun>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Spun&&(identical(other.gameId, gameId) || other.gameId == gameId));
}
@override
int get hashCode {
return Object.hash(runtimeType,gameId);
}
@override
String toString() {
return 'GameSpinEvent.spun(gameId: $gameId)';
}
}
/// @nodoc
abstract mixin class _$SpunCopyWith<$Res> implements $GameSpinEventCopyWith<$Res> {
factory _$SpunCopyWith(_Spun value, $Res Function(_Spun) _then) = __$SpunCopyWithImpl;
@override @useResult
$Res call({
String gameId
});
}
/// @nodoc
class __$SpunCopyWithImpl<$Res>
implements _$SpunCopyWith<$Res> {
__$SpunCopyWithImpl(this._self, this._then);
final _Spun _self;
final $Res Function(_Spun) _then;
/// Create a copy of GameSpinEvent
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? gameId = null,}) {
return _then(_Spun(
null == gameId ? _self.gameId : gameId // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
mixin _$GameSpinState {
bool get isSpinning; Option<Either<GameFailure, SpinResult>> get failureOrResultOption;
/// Create a copy of GameSpinState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$GameSpinStateCopyWith<GameSpinState> get copyWith => _$GameSpinStateCopyWithImpl<GameSpinState>(this as GameSpinState, _$identity);
@override
bool operator ==(Object other) {
final _this = this as GameSpinState;
return identical(this, other) || (other.runtimeType == runtimeType&&other is GameSpinState&&(identical(other.isSpinning, _this.isSpinning) || other.isSpinning == _this.isSpinning)&&(identical(other.failureOrResultOption, _this.failureOrResultOption) || other.failureOrResultOption == _this.failureOrResultOption));
}
@override
int get hashCode {
final _this = this as GameSpinState;
return Object.hash(runtimeType,_this.isSpinning,_this.failureOrResultOption);
}
@override
String toString() {
final _this = this as GameSpinState;
return 'GameSpinState(isSpinning: ${_this.isSpinning}, failureOrResultOption: ${_this.failureOrResultOption})';
}
}
/// @nodoc
abstract mixin class $GameSpinStateCopyWith<$Res> {
factory $GameSpinStateCopyWith(GameSpinState value, $Res Function(GameSpinState) _then) = _$GameSpinStateCopyWithImpl;
@useResult
$Res call({
bool isSpinning, Option<Either<GameFailure, SpinResult>> failureOrResultOption
});
}
/// @nodoc
class _$GameSpinStateCopyWithImpl<$Res>
implements $GameSpinStateCopyWith<$Res> {
_$GameSpinStateCopyWithImpl(this._self, this._then);
final GameSpinState _self;
final $Res Function(GameSpinState) _then;
/// Create a copy of GameSpinState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? isSpinning = null,Object? failureOrResultOption = null,}) {
return _then(GameSpinState(
isSpinning: null == isSpinning ? _self.isSpinning : isSpinning // ignore: cast_nullable_to_non_nullable
as bool,failureOrResultOption: null == failureOrResultOption ? _self.failureOrResultOption : failureOrResultOption // ignore: cast_nullable_to_non_nullable
as Option<Either<GameFailure, SpinResult>>,
));
}
}
/// Adds pattern-matching-related methods to [GameSpinState].
extension GameSpinStatePatterns on GameSpinState {
/// 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( _GameSpinState value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _GameSpinState() 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( _GameSpinState value) $default,){
final _that = this;
switch (_that) {
case _GameSpinState():
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( _GameSpinState value)? $default,){
final _that = this;
switch (_that) {
case _GameSpinState() 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( bool isSpinning, Option<Either<GameFailure, SpinResult>> failureOrResultOption)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _GameSpinState() when $default != null:
return $default(_that.isSpinning,_that.failureOrResultOption);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( bool isSpinning, Option<Either<GameFailure, SpinResult>> failureOrResultOption) $default,) {final _that = this;
switch (_that) {
case _GameSpinState():
return $default(_that.isSpinning,_that.failureOrResultOption);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( bool isSpinning, Option<Either<GameFailure, SpinResult>> failureOrResultOption)? $default,) {final _that = this;
switch (_that) {
case _GameSpinState() when $default != null:
return $default(_that.isSpinning,_that.failureOrResultOption);case _:
return null;
}
}
}
/// @nodoc
class _GameSpinState implements GameSpinState {
const _GameSpinState({this.isSpinning = false, required this.failureOrResultOption});
@override@JsonKey() final bool isSpinning;
@override final Option<Either<GameFailure, SpinResult>> failureOrResultOption;
/// Create a copy of GameSpinState
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$GameSpinStateCopyWith<_GameSpinState> get copyWith => __$GameSpinStateCopyWithImpl<_GameSpinState>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _GameSpinState&&(identical(other.isSpinning, isSpinning) || other.isSpinning == isSpinning)&&(identical(other.failureOrResultOption, failureOrResultOption) || other.failureOrResultOption == failureOrResultOption));
}
@override
int get hashCode {
return Object.hash(runtimeType,isSpinning,failureOrResultOption);
}
@override
String toString() {
return 'GameSpinState(isSpinning: $isSpinning, failureOrResultOption: $failureOrResultOption)';
}
}
/// @nodoc
abstract mixin class _$GameSpinStateCopyWith<$Res> implements $GameSpinStateCopyWith<$Res> {
factory _$GameSpinStateCopyWith(_GameSpinState value, $Res Function(_GameSpinState) _then) = __$GameSpinStateCopyWithImpl;
@override @useResult
$Res call({
bool isSpinning, Option<Either<GameFailure, SpinResult>> failureOrResultOption
});
}
/// @nodoc
class __$GameSpinStateCopyWithImpl<$Res>
implements _$GameSpinStateCopyWith<$Res> {
__$GameSpinStateCopyWithImpl(this._self, this._then);
final _GameSpinState _self;
final $Res Function(_GameSpinState) _then;
/// Create a copy of GameSpinState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? isSpinning = null,Object? failureOrResultOption = null,}) {
return _then(_GameSpinState(
isSpinning: null == isSpinning ? _self.isSpinning : isSpinning // ignore: cast_nullable_to_non_nullable
as bool,failureOrResultOption: null == failureOrResultOption ? _self.failureOrResultOption : failureOrResultOption // ignore: cast_nullable_to_non_nullable
as Option<Either<GameFailure, SpinResult>>,
));
}
}
// dart format on
@@ -1,6 +0,0 @@
part of 'game_spin_bloc.dart';
@freezed
abstract class GameSpinEvent with _$GameSpinEvent {
const factory GameSpinEvent.spun(String gameId) = _Spun;
}
@@ -1,12 +0,0 @@
part of 'game_spin_bloc.dart';
@freezed
abstract class GameSpinState with _$GameSpinState {
const factory GameSpinState({
@Default(false) bool isSpinning,
required Option<Either<GameFailure, SpinResult>> failureOrResultOption,
}) = _GameSpinState;
factory GameSpinState.initial() =>
GameSpinState(failureOrResultOption: none());
}
@@ -0,0 +1,40 @@
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 'voucher_loader_event.dart';
part 'voucher_loader_state.dart';
part 'voucher_loader_bloc.freezed.dart';
/// Katalog voucher yang bisa ditukar (§9.1).
@injectable
class VoucherLoaderBloc extends Bloc<VoucherLoaderEvent, VoucherLoaderState> {
final IVoucherRepository _repository;
VoucherLoaderBloc(this._repository) : super(VoucherLoaderState.initial()) {
on<VoucherLoaderEvent>(_onVoucherLoaderEvent);
}
Future<void> _onVoucherLoaderEvent(
VoucherLoaderEvent event,
Emitter<VoucherLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(state.copyWith(isFetching: true, failureOption: none()));
final result = await _repository.getVouchers();
final data = result.fold(
(f) => state.copyWith(failureOption: optionOf(f)),
(vouchers) => state.copyWith(vouchers: vouchers, hasLoaded: true),
);
emit(data.copyWith(isFetching: false));
},
);
}
}
@@ -3,7 +3,7 @@
// 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 'ferris_wheel_loader_bloc.dart';
part of 'voucher_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
@@ -13,7 +13,7 @@ part of 'ferris_wheel_loader_bloc.dart';
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$FerrisWheelLoaderEvent {
mixin _$VoucherLoaderEvent {
@@ -21,7 +21,7 @@ mixin _$FerrisWheelLoaderEvent {
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is FerrisWheelLoaderEvent);
return identical(this, other) || (other.runtimeType == runtimeType&&other is VoucherLoaderEvent);
}
@@ -30,20 +30,20 @@ int get hashCode => runtimeType.hashCode;
@override
String toString() {
return 'FerrisWheelLoaderEvent()';
return 'VoucherLoaderEvent()';
}
}
/// @nodoc
class $FerrisWheelLoaderEventCopyWith<$Res> {
$FerrisWheelLoaderEventCopyWith(FerrisWheelLoaderEvent _, $Res Function(FerrisWheelLoaderEvent) __);
class $VoucherLoaderEventCopyWith<$Res> {
$VoucherLoaderEventCopyWith(VoucherLoaderEvent _, $Res Function(VoucherLoaderEvent) __);
}
/// Adds pattern-matching-related methods to [FerrisWheelLoaderEvent].
extension FerrisWheelLoaderEventPatterns on FerrisWheelLoaderEvent {
/// Adds pattern-matching-related methods to [VoucherLoaderEvent].
extension VoucherLoaderEventPatterns on VoucherLoaderEvent {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
@@ -175,7 +175,7 @@ return fetched();case _:
/// @nodoc
class _Fetched implements FerrisWheelLoaderEvent {
class _Fetched implements VoucherLoaderEvent {
const _Fetched();
@@ -195,7 +195,7 @@ int get hashCode => runtimeType.hashCode;
@override
String toString() {
return 'FerrisWheelLoaderEvent.fetched()';
return 'VoucherLoaderEvent.fetched()';
}
@@ -205,84 +205,76 @@ String toString() {
/// @nodoc
mixin _$FerrisWheelLoaderState {
mixin _$VoucherLoaderState {
Game get ferrisWheel; Option<GameFailure> get failureOptionFerrisWheel; bool get isFetching;
/// Create a copy of FerrisWheelLoaderState
List<Voucher> get vouchers; Option<WalletFailure> get failureOption; bool get isFetching; bool get hasLoaded;
/// Create a copy of VoucherLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$FerrisWheelLoaderStateCopyWith<FerrisWheelLoaderState> get copyWith => _$FerrisWheelLoaderStateCopyWithImpl<FerrisWheelLoaderState>(this as FerrisWheelLoaderState, _$identity);
$VoucherLoaderStateCopyWith<VoucherLoaderState> get copyWith => _$VoucherLoaderStateCopyWithImpl<VoucherLoaderState>(this as VoucherLoaderState, _$identity);
@override
bool operator ==(Object other) {
final _this = this as FerrisWheelLoaderState;
return identical(this, other) || (other.runtimeType == runtimeType&&other is FerrisWheelLoaderState&&(identical(other.ferrisWheel, _this.ferrisWheel) || other.ferrisWheel == _this.ferrisWheel)&&(identical(other.failureOptionFerrisWheel, _this.failureOptionFerrisWheel) || other.failureOptionFerrisWheel == _this.failureOptionFerrisWheel)&&(identical(other.isFetching, _this.isFetching) || other.isFetching == _this.isFetching));
final _this = this as VoucherLoaderState;
return identical(this, other) || (other.runtimeType == runtimeType&&other is VoucherLoaderState&&const DeepCollectionEquality().equals(other.vouchers, _this.vouchers)&&(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 FerrisWheelLoaderState;
return Object.hash(runtimeType,_this.ferrisWheel,_this.failureOptionFerrisWheel,_this.isFetching);
final _this = this as VoucherLoaderState;
return Object.hash(runtimeType,const DeepCollectionEquality().hash(_this.vouchers),_this.failureOption,_this.isFetching,_this.hasLoaded);
}
@override
String toString() {
final _this = this as FerrisWheelLoaderState;
return 'FerrisWheelLoaderState(ferrisWheel: ${_this.ferrisWheel}, failureOptionFerrisWheel: ${_this.failureOptionFerrisWheel}, isFetching: ${_this.isFetching})';
final _this = this as VoucherLoaderState;
return 'VoucherLoaderState(vouchers: ${_this.vouchers}, failureOption: ${_this.failureOption}, isFetching: ${_this.isFetching}, hasLoaded: ${_this.hasLoaded})';
}
}
/// @nodoc
abstract mixin class $FerrisWheelLoaderStateCopyWith<$Res> {
factory $FerrisWheelLoaderStateCopyWith(FerrisWheelLoaderState value, $Res Function(FerrisWheelLoaderState) _then) = _$FerrisWheelLoaderStateCopyWithImpl;
abstract mixin class $VoucherLoaderStateCopyWith<$Res> {
factory $VoucherLoaderStateCopyWith(VoucherLoaderState value, $Res Function(VoucherLoaderState) _then) = _$VoucherLoaderStateCopyWithImpl;
@useResult
$Res call({
Game ferrisWheel, Option<GameFailure> failureOptionFerrisWheel, bool isFetching
List<Voucher> vouchers, Option<WalletFailure> failureOption, bool isFetching, bool hasLoaded
});
$GameCopyWith<$Res> get ferrisWheel;
}
/// @nodoc
class _$FerrisWheelLoaderStateCopyWithImpl<$Res>
implements $FerrisWheelLoaderStateCopyWith<$Res> {
_$FerrisWheelLoaderStateCopyWithImpl(this._self, this._then);
class _$VoucherLoaderStateCopyWithImpl<$Res>
implements $VoucherLoaderStateCopyWith<$Res> {
_$VoucherLoaderStateCopyWithImpl(this._self, this._then);
final FerrisWheelLoaderState _self;
final $Res Function(FerrisWheelLoaderState) _then;
final VoucherLoaderState _self;
final $Res Function(VoucherLoaderState) _then;
/// Create a copy of FerrisWheelLoaderState
/// Create a copy of VoucherLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? ferrisWheel = null,Object? failureOptionFerrisWheel = null,Object? isFetching = null,}) {
return _then(FerrisWheelLoaderState(
ferrisWheel: null == ferrisWheel ? _self.ferrisWheel : ferrisWheel // ignore: cast_nullable_to_non_nullable
as Game,failureOptionFerrisWheel: null == failureOptionFerrisWheel ? _self.failureOptionFerrisWheel : failureOptionFerrisWheel // ignore: cast_nullable_to_non_nullable
as Option<GameFailure>,isFetching: null == isFetching ? _self.isFetching : isFetching // ignore: cast_nullable_to_non_nullable
@pragma('vm:prefer-inline') @override $Res call({Object? vouchers = null,Object? failureOption = null,Object? isFetching = null,Object? hasLoaded = null,}) {
return _then(VoucherLoaderState(
vouchers: null == vouchers ? _self.vouchers : vouchers // ignore: cast_nullable_to_non_nullable
as List<Voucher>,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 FerrisWheelLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$GameCopyWith<$Res> get ferrisWheel {
return $GameCopyWith<$Res>(_self.ferrisWheel, (value) {
return _then(_self.copyWith(ferrisWheel: value));
});
}
}
/// Adds pattern-matching-related methods to [FerrisWheelLoaderState].
extension FerrisWheelLoaderStatePatterns on FerrisWheelLoaderState {
/// Adds pattern-matching-related methods to [VoucherLoaderState].
extension VoucherLoaderStatePatterns on VoucherLoaderState {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
@@ -295,10 +287,10 @@ extension FerrisWheelLoaderStatePatterns on FerrisWheelLoaderState {
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _FerrisWheelLoaderState value)? $default,{required TResult orElse(),}){
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _VoucherLoaderState value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _FerrisWheelLoaderState() when $default != null:
case _VoucherLoaderState() when $default != null:
return $default(_that);case _:
return orElse();
@@ -317,10 +309,10 @@ return $default(_that);case _:
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _FerrisWheelLoaderState value) $default,){
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _VoucherLoaderState value) $default,){
final _that = this;
switch (_that) {
case _FerrisWheelLoaderState():
case _VoucherLoaderState():
return $default(_that);case _:
throw StateError('Unexpected subclass');
@@ -338,10 +330,10 @@ return $default(_that);case _:
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _FerrisWheelLoaderState value)? $default,){
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _VoucherLoaderState value)? $default,){
final _that = this;
switch (_that) {
case _FerrisWheelLoaderState() when $default != null:
case _VoucherLoaderState() when $default != null:
return $default(_that);case _:
return null;
@@ -359,10 +351,10 @@ return $default(_that);case _:
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( Game ferrisWheel, Option<GameFailure> failureOptionFerrisWheel, bool isFetching)? $default,{required TResult orElse(),}) {final _that = this;
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<Voucher> vouchers, Option<WalletFailure> failureOption, bool isFetching, bool hasLoaded)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _FerrisWheelLoaderState() when $default != null:
return $default(_that.ferrisWheel,_that.failureOptionFerrisWheel,_that.isFetching);case _:
case _VoucherLoaderState() when $default != null:
return $default(_that.vouchers,_that.failureOption,_that.isFetching,_that.hasLoaded);case _:
return orElse();
}
@@ -380,10 +372,10 @@ return $default(_that.ferrisWheel,_that.failureOptionFerrisWheel,_that.isFetchin
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( Game ferrisWheel, Option<GameFailure> failureOptionFerrisWheel, bool isFetching) $default,) {final _that = this;
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<Voucher> vouchers, Option<WalletFailure> failureOption, bool isFetching, bool hasLoaded) $default,) {final _that = this;
switch (_that) {
case _FerrisWheelLoaderState():
return $default(_that.ferrisWheel,_that.failureOptionFerrisWheel,_that.isFetching);case _:
case _VoucherLoaderState():
return $default(_that.vouchers,_that.failureOption,_that.isFetching,_that.hasLoaded);case _:
throw StateError('Unexpected subclass');
}
@@ -400,10 +392,10 @@ return $default(_that.ferrisWheel,_that.failureOptionFerrisWheel,_that.isFetchin
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( Game ferrisWheel, Option<GameFailure> failureOptionFerrisWheel, bool isFetching)? $default,) {final _that = this;
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<Voucher> vouchers, Option<WalletFailure> failureOption, bool isFetching, bool hasLoaded)? $default,) {final _that = this;
switch (_that) {
case _FerrisWheelLoaderState() when $default != null:
return $default(_that.ferrisWheel,_that.failureOptionFerrisWheel,_that.isFetching);case _:
case _VoucherLoaderState() when $default != null:
return $default(_that.vouchers,_that.failureOption,_that.isFetching,_that.hasLoaded);case _:
return null;
}
@@ -414,82 +406,81 @@ return $default(_that.ferrisWheel,_that.failureOptionFerrisWheel,_that.isFetchin
/// @nodoc
class _FerrisWheelLoaderState implements FerrisWheelLoaderState {
const _FerrisWheelLoaderState({required this.ferrisWheel, required this.failureOptionFerrisWheel, this.isFetching = false});
class _VoucherLoaderState implements VoucherLoaderState {
const _VoucherLoaderState({required List<Voucher> vouchers, required this.failureOption, this.isFetching = false, this.hasLoaded = false}): _vouchers = vouchers;
@override final Game ferrisWheel;
@override final Option<GameFailure> failureOptionFerrisWheel;
@override@JsonKey() final bool isFetching;
final List<Voucher> _vouchers;
@override List<Voucher> get vouchers {
if (_vouchers is EqualUnmodifiableListView) return _vouchers;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_vouchers);
}
/// Create a copy of FerrisWheelLoaderState
@override final Option<WalletFailure> failureOption;
@override@JsonKey() final bool isFetching;
@override@JsonKey() final bool hasLoaded;
/// Create a copy of VoucherLoaderState
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$FerrisWheelLoaderStateCopyWith<_FerrisWheelLoaderState> get copyWith => __$FerrisWheelLoaderStateCopyWithImpl<_FerrisWheelLoaderState>(this, _$identity);
_$VoucherLoaderStateCopyWith<_VoucherLoaderState> get copyWith => __$VoucherLoaderStateCopyWithImpl<_VoucherLoaderState>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _FerrisWheelLoaderState&&(identical(other.ferrisWheel, ferrisWheel) || other.ferrisWheel == ferrisWheel)&&(identical(other.failureOptionFerrisWheel, failureOptionFerrisWheel) || other.failureOptionFerrisWheel == failureOptionFerrisWheel)&&(identical(other.isFetching, isFetching) || other.isFetching == isFetching));
return identical(this, other) || (other.runtimeType == runtimeType&&other is _VoucherLoaderState&&const DeepCollectionEquality().equals(other.vouchers, _vouchers)&&(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,ferrisWheel,failureOptionFerrisWheel,isFetching);
return Object.hash(runtimeType,const DeepCollectionEquality().hash(_vouchers),failureOption,isFetching,hasLoaded);
}
@override
String toString() {
return 'FerrisWheelLoaderState(ferrisWheel: $ferrisWheel, failureOptionFerrisWheel: $failureOptionFerrisWheel, isFetching: $isFetching)';
return 'VoucherLoaderState(vouchers: $vouchers, failureOption: $failureOption, isFetching: $isFetching, hasLoaded: $hasLoaded)';
}
}
/// @nodoc
abstract mixin class _$FerrisWheelLoaderStateCopyWith<$Res> implements $FerrisWheelLoaderStateCopyWith<$Res> {
factory _$FerrisWheelLoaderStateCopyWith(_FerrisWheelLoaderState value, $Res Function(_FerrisWheelLoaderState) _then) = __$FerrisWheelLoaderStateCopyWithImpl;
abstract mixin class _$VoucherLoaderStateCopyWith<$Res> implements $VoucherLoaderStateCopyWith<$Res> {
factory _$VoucherLoaderStateCopyWith(_VoucherLoaderState value, $Res Function(_VoucherLoaderState) _then) = __$VoucherLoaderStateCopyWithImpl;
@override @useResult
$Res call({
Game ferrisWheel, Option<GameFailure> failureOptionFerrisWheel, bool isFetching
List<Voucher> vouchers, Option<WalletFailure> failureOption, bool isFetching, bool hasLoaded
});
@override $GameCopyWith<$Res> get ferrisWheel;
}
/// @nodoc
class __$FerrisWheelLoaderStateCopyWithImpl<$Res>
implements _$FerrisWheelLoaderStateCopyWith<$Res> {
__$FerrisWheelLoaderStateCopyWithImpl(this._self, this._then);
class __$VoucherLoaderStateCopyWithImpl<$Res>
implements _$VoucherLoaderStateCopyWith<$Res> {
__$VoucherLoaderStateCopyWithImpl(this._self, this._then);
final _FerrisWheelLoaderState _self;
final $Res Function(_FerrisWheelLoaderState) _then;
final _VoucherLoaderState _self;
final $Res Function(_VoucherLoaderState) _then;
/// Create a copy of FerrisWheelLoaderState
/// Create a copy of VoucherLoaderState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? ferrisWheel = null,Object? failureOptionFerrisWheel = null,Object? isFetching = null,}) {
return _then(_FerrisWheelLoaderState(
ferrisWheel: null == ferrisWheel ? _self.ferrisWheel : ferrisWheel // ignore: cast_nullable_to_non_nullable
as Game,failureOptionFerrisWheel: null == failureOptionFerrisWheel ? _self.failureOptionFerrisWheel : failureOptionFerrisWheel // ignore: cast_nullable_to_non_nullable
as Option<GameFailure>,isFetching: null == isFetching ? _self.isFetching : isFetching // ignore: cast_nullable_to_non_nullable
@override @pragma('vm:prefer-inline') $Res call({Object? vouchers = null,Object? failureOption = null,Object? isFetching = null,Object? hasLoaded = null,}) {
return _then(_VoucherLoaderState(
vouchers: null == vouchers ? _self._vouchers : vouchers // ignore: cast_nullable_to_non_nullable
as List<Voucher>,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 FerrisWheelLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$GameCopyWith<$Res> get ferrisWheel {
return $GameCopyWith<$Res>(_self.ferrisWheel, (value) {
return _then(_self.copyWith(ferrisWheel: value));
});
}
}
// dart format on
@@ -0,0 +1,6 @@
part of 'voucher_loader_bloc.dart';
@freezed
abstract class VoucherLoaderEvent with _$VoucherLoaderEvent {
const factory VoucherLoaderEvent.fetched() = _Fetched;
}
@@ -0,0 +1,14 @@
part of 'voucher_loader_bloc.dart';
@freezed
abstract class VoucherLoaderState with _$VoucherLoaderState {
const factory VoucherLoaderState({
required List<Voucher> vouchers,
required Option<WalletFailure> failureOption,
@Default(false) bool isFetching,
@Default(false) bool hasLoaded,
}) = _VoucherLoaderState;
factory VoucherLoaderState.initial() =>
VoucherLoaderState(vouchers: const [], failureOption: none());
}
@@ -0,0 +1,63 @@
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 'voucher_redeem_form_event.dart';
part 'voucher_redeem_form_state.dart';
part 'voucher_redeem_form_bloc.freezed.dart';
/// Tukar EnakPoint ke satu voucher (§9.2). Satu bloc per voucher, supaya
/// `Idempotency-Key` tidak terbawa ke voucher lain.
@injectable
class VoucherRedeemFormBloc
extends Bloc<VoucherRedeemFormEvent, VoucherRedeemFormState> {
final IVoucherRepository _repository;
VoucherRedeemFormBloc(this._repository)
: super(VoucherRedeemFormState.initial()) {
on<VoucherRedeemFormEvent>(_onVoucherRedeemFormEvent);
}
Future<void> _onVoucherRedeemFormEvent(
VoucherRedeemFormEvent event,
Emitter<VoucherRedeemFormState> emit,
) {
return event.map(
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.redeem(
voucherId: e.voucherId,
pin: e.pin,
idempotencyKey: key,
);
emit(
result
.fold(
(f) => state.copyWith(
failureOption: optionOf(f),
idempotencyKey: f.isNetworkError ? key : null,
),
(redeemResult) =>
state.copyWith(result: redeemResult, idempotencyKey: null),
)
.copyWith(isSubmitting: false),
);
},
);
}
}
@@ -0,0 +1,579 @@
// 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 'voucher_redeem_form_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$VoucherRedeemFormEvent {
String get voucherId; String get pin;
/// Create a copy of VoucherRedeemFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$VoucherRedeemFormEventCopyWith<VoucherRedeemFormEvent> get copyWith => _$VoucherRedeemFormEventCopyWithImpl<VoucherRedeemFormEvent>(this as VoucherRedeemFormEvent, _$identity);
@override
bool operator ==(Object other) {
final _this = this as VoucherRedeemFormEvent;
return identical(this, other) || (other.runtimeType == runtimeType&&other is VoucherRedeemFormEvent&&(identical(other.voucherId, _this.voucherId) || other.voucherId == _this.voucherId)&&(identical(other.pin, _this.pin) || other.pin == _this.pin));
}
@override
int get hashCode {
final _this = this as VoucherRedeemFormEvent;
return Object.hash(runtimeType,_this.voucherId,_this.pin);
}
@override
String toString() {
final _this = this as VoucherRedeemFormEvent;
return 'VoucherRedeemFormEvent(voucherId: ${_this.voucherId}, pin: ${_this.pin})';
}
}
/// @nodoc
abstract mixin class $VoucherRedeemFormEventCopyWith<$Res> {
factory $VoucherRedeemFormEventCopyWith(VoucherRedeemFormEvent value, $Res Function(VoucherRedeemFormEvent) _then) = _$VoucherRedeemFormEventCopyWithImpl;
@useResult
$Res call({
String voucherId, String pin
});
}
/// @nodoc
class _$VoucherRedeemFormEventCopyWithImpl<$Res>
implements $VoucherRedeemFormEventCopyWith<$Res> {
_$VoucherRedeemFormEventCopyWithImpl(this._self, this._then);
final VoucherRedeemFormEvent _self;
final $Res Function(VoucherRedeemFormEvent) _then;
/// Create a copy of VoucherRedeemFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? voucherId = null,Object? pin = null,}) {
return _then(VoucherRedeemFormEvent.submitted(
voucherId: null == voucherId ? _self.voucherId : voucherId // ignore: cast_nullable_to_non_nullable
as String,pin: null == pin ? _self.pin : pin // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [VoucherRedeemFormEvent].
extension VoucherRedeemFormEventPatterns on VoucherRedeemFormEvent {
/// 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,required TResult orElse(),}){
final _that = this;
switch (_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( _Submitted value) submitted,}){
final _that = this;
switch (_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( _Submitted value)? submitted,}){
final _that = this;
switch (_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( String voucherId, String pin)? submitted,required TResult orElse(),}) {final _that = this;
switch (_that) {
case _Submitted() when submitted != null:
return submitted(_that.voucherId,_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( String voucherId, String pin) submitted,}) {final _that = this;
switch (_that) {
case _Submitted():
return submitted(_that.voucherId,_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( String voucherId, String pin)? submitted,}) {final _that = this;
switch (_that) {
case _Submitted() when submitted != null:
return submitted(_that.voucherId,_that.pin);case _:
return null;
}
}
}
/// @nodoc
class _Submitted implements VoucherRedeemFormEvent {
const _Submitted({required this.voucherId, required this.pin});
@override final String voucherId;
@override final String pin;
/// Create a copy of VoucherRedeemFormEvent
/// with the given fields replaced by the non-null parameter values.
@override @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.voucherId, voucherId) || other.voucherId == voucherId)&&(identical(other.pin, pin) || other.pin == pin));
}
@override
int get hashCode {
return Object.hash(runtimeType,voucherId,pin);
}
@override
String toString() {
return 'VoucherRedeemFormEvent.submitted(voucherId: $voucherId, pin: $pin)';
}
}
/// @nodoc
abstract mixin class _$SubmittedCopyWith<$Res> implements $VoucherRedeemFormEventCopyWith<$Res> {
factory _$SubmittedCopyWith(_Submitted value, $Res Function(_Submitted) _then) = __$SubmittedCopyWithImpl;
@override @useResult
$Res call({
String voucherId, 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 VoucherRedeemFormEvent
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? voucherId = null,Object? pin = null,}) {
return _then(_Submitted(
voucherId: null == voucherId ? _self.voucherId : voucherId // ignore: cast_nullable_to_non_nullable
as String,pin: null == pin ? _self.pin : pin // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
mixin _$VoucherRedeemFormState {
VoucherRedeemResult? get result; Option<WalletFailure> get failureOption; bool get isSubmitting; String? get idempotencyKey;
/// Create a copy of VoucherRedeemFormState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$VoucherRedeemFormStateCopyWith<VoucherRedeemFormState> get copyWith => _$VoucherRedeemFormStateCopyWithImpl<VoucherRedeemFormState>(this as VoucherRedeemFormState, _$identity);
@override
bool operator ==(Object other) {
final _this = this as VoucherRedeemFormState;
return identical(this, other) || (other.runtimeType == runtimeType&&other is VoucherRedeemFormState&&(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 VoucherRedeemFormState;
return Object.hash(runtimeType,_this.result,_this.failureOption,_this.isSubmitting,_this.idempotencyKey);
}
@override
String toString() {
final _this = this as VoucherRedeemFormState;
return 'VoucherRedeemFormState(result: ${_this.result}, failureOption: ${_this.failureOption}, isSubmitting: ${_this.isSubmitting}, idempotencyKey: ${_this.idempotencyKey})';
}
}
/// @nodoc
abstract mixin class $VoucherRedeemFormStateCopyWith<$Res> {
factory $VoucherRedeemFormStateCopyWith(VoucherRedeemFormState value, $Res Function(VoucherRedeemFormState) _then) = _$VoucherRedeemFormStateCopyWithImpl;
@useResult
$Res call({
VoucherRedeemResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey
});
$VoucherRedeemResultCopyWith<$Res>? get result;
}
/// @nodoc
class _$VoucherRedeemFormStateCopyWithImpl<$Res>
implements $VoucherRedeemFormStateCopyWith<$Res> {
_$VoucherRedeemFormStateCopyWithImpl(this._self, this._then);
final VoucherRedeemFormState _self;
final $Res Function(VoucherRedeemFormState) _then;
/// Create a copy of VoucherRedeemFormState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? result = freezed,Object? failureOption = null,Object? isSubmitting = null,Object? idempotencyKey = freezed,}) {
return _then(VoucherRedeemFormState(
result: freezed == result ? _self.result : result // ignore: cast_nullable_to_non_nullable
as VoucherRedeemResult?,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 VoucherRedeemFormState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$VoucherRedeemResultCopyWith<$Res>? get result {
if (_self.result == null) {
return null;
}
return $VoucherRedeemResultCopyWith<$Res>(_self.result!, (value) {
return _then(_self.copyWith(result: value));
});
}
}
/// Adds pattern-matching-related methods to [VoucherRedeemFormState].
extension VoucherRedeemFormStatePatterns on VoucherRedeemFormState {
/// 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( _VoucherRedeemFormState value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _VoucherRedeemFormState() 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( _VoucherRedeemFormState value) $default,){
final _that = this;
switch (_that) {
case _VoucherRedeemFormState():
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( _VoucherRedeemFormState value)? $default,){
final _that = this;
switch (_that) {
case _VoucherRedeemFormState() 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( VoucherRedeemResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _VoucherRedeemFormState() when $default != null:
return $default(_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( VoucherRedeemResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey) $default,) {final _that = this;
switch (_that) {
case _VoucherRedeemFormState():
return $default(_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( VoucherRedeemResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey)? $default,) {final _that = this;
switch (_that) {
case _VoucherRedeemFormState() when $default != null:
return $default(_that.result,_that.failureOption,_that.isSubmitting,_that.idempotencyKey);case _:
return null;
}
}
}
/// @nodoc
class _VoucherRedeemFormState implements VoucherRedeemFormState {
const _VoucherRedeemFormState({this.result, required this.failureOption, this.isSubmitting = false, this.idempotencyKey});
@override final VoucherRedeemResult? result;
@override final Option<WalletFailure> failureOption;
@override@JsonKey() final bool isSubmitting;
@override final String? idempotencyKey;
/// Create a copy of VoucherRedeemFormState
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$VoucherRedeemFormStateCopyWith<_VoucherRedeemFormState> get copyWith => __$VoucherRedeemFormStateCopyWithImpl<_VoucherRedeemFormState>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _VoucherRedeemFormState&&(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,result,failureOption,isSubmitting,idempotencyKey);
}
@override
String toString() {
return 'VoucherRedeemFormState(result: $result, failureOption: $failureOption, isSubmitting: $isSubmitting, idempotencyKey: $idempotencyKey)';
}
}
/// @nodoc
abstract mixin class _$VoucherRedeemFormStateCopyWith<$Res> implements $VoucherRedeemFormStateCopyWith<$Res> {
factory _$VoucherRedeemFormStateCopyWith(_VoucherRedeemFormState value, $Res Function(_VoucherRedeemFormState) _then) = __$VoucherRedeemFormStateCopyWithImpl;
@override @useResult
$Res call({
VoucherRedeemResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey
});
@override $VoucherRedeemResultCopyWith<$Res>? get result;
}
/// @nodoc
class __$VoucherRedeemFormStateCopyWithImpl<$Res>
implements _$VoucherRedeemFormStateCopyWith<$Res> {
__$VoucherRedeemFormStateCopyWithImpl(this._self, this._then);
final _VoucherRedeemFormState _self;
final $Res Function(_VoucherRedeemFormState) _then;
/// Create a copy of VoucherRedeemFormState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? result = freezed,Object? failureOption = null,Object? isSubmitting = null,Object? idempotencyKey = freezed,}) {
return _then(_VoucherRedeemFormState(
result: freezed == result ? _self.result : result // ignore: cast_nullable_to_non_nullable
as VoucherRedeemResult?,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 VoucherRedeemFormState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$VoucherRedeemResultCopyWith<$Res>? get result {
if (_self.result == null) {
return null;
}
return $VoucherRedeemResultCopyWith<$Res>(_self.result!, (value) {
return _then(_self.copyWith(result: value));
});
}
}
// dart format on
@@ -0,0 +1,10 @@
part of 'voucher_redeem_form_bloc.dart';
@freezed
abstract class VoucherRedeemFormEvent with _$VoucherRedeemFormEvent {
/// [pin] hanya diteruskan ke API, tidak disimpan di state.
const factory VoucherRedeemFormEvent.submitted({
required String voucherId,
required String pin,
}) = _Submitted;
}
@@ -0,0 +1,14 @@
part of 'voucher_redeem_form_bloc.dart';
@freezed
abstract class VoucherRedeemFormState with _$VoucherRedeemFormState {
const factory VoucherRedeemFormState({
VoucherRedeemResult? result,
required Option<WalletFailure> failureOption,
@Default(false) bool isSubmitting,
String? idempotencyKey,
}) = _VoucherRedeemFormState;
factory VoucherRedeemFormState.initial() =>
VoucherRedeemFormState(failureOption: none());
}
@@ -0,0 +1,73 @@
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 'voucher_redemption_loader_event.dart';
part 'voucher_redemption_loader_state.dart';
part 'voucher_redemption_loader_bloc.freezed.dart';
/// "Voucher saya" (§9.3).
@injectable
class VoucherRedemptionLoaderBloc
extends Bloc<VoucherRedemptionLoaderEvent, VoucherRedemptionLoaderState> {
final IVoucherRepository _repository;
static const int _limit = 20;
VoucherRedemptionLoaderBloc(this._repository)
: super(VoucherRedemptionLoaderState.initial()) {
on<VoucherRedemptionLoaderEvent>(_onVoucherRedemptionLoaderEvent);
}
Future<void> _onVoucherRedemptionLoaderEvent(
VoucherRedemptionLoaderEvent event,
Emitter<VoucherRedemptionLoaderState> emit,
) {
return event.map(
refreshed: (e) async {
emit(state.copyWith(isFetching: true, failureOption: none()));
final result = await _repository.getRedemptions(page: 1, limit: _limit);
emit(
result
.fold(
(f) => state.copyWith(failureOption: optionOf(f)),
(page) => state.copyWith(
items: page.items,
page: page.page,
totalPages: page.totalPages,
hasLoaded: true,
),
)
.copyWith(isFetching: false),
);
},
loadedMore: (e) async {
if (state.isFetching || state.isLoadingMore || !state.hasMore) return;
emit(state.copyWith(isLoadingMore: true, failureOption: none()));
final result = await _repository.getRedemptions(
page: state.page + 1,
limit: _limit,
);
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),
);
},
);
}
}
@@ -0,0 +1,533 @@
// 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 'voucher_redemption_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$VoucherRedemptionLoaderEvent {
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is VoucherRedemptionLoaderEvent);
}
@override
int get hashCode => runtimeType.hashCode;
@override
String toString() {
return 'VoucherRedemptionLoaderEvent()';
}
}
/// @nodoc
class $VoucherRedemptionLoaderEventCopyWith<$Res> {
$VoucherRedemptionLoaderEventCopyWith(VoucherRedemptionLoaderEvent _, $Res Function(VoucherRedemptionLoaderEvent) __);
}
/// Adds pattern-matching-related methods to [VoucherRedemptionLoaderEvent].
extension VoucherRedemptionLoaderEventPatterns on VoucherRedemptionLoaderEvent {
/// 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( _Refreshed value)? refreshed,TResult Function( _LoadedMore value)? loadedMore,required TResult orElse(),}){
final _that = this;
switch (_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( _Refreshed value) refreshed,required TResult Function( _LoadedMore value) loadedMore,}){
final _that = this;
switch (_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( _Refreshed value)? refreshed,TResult? Function( _LoadedMore value)? loadedMore,}){
final _that = this;
switch (_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()? refreshed,TResult Function()? loadedMore,required TResult orElse(),}) {final _that = this;
switch (_that) {
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() refreshed,required TResult Function() loadedMore,}) {final _that = this;
switch (_that) {
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()? refreshed,TResult? Function()? loadedMore,}) {final _that = this;
switch (_that) {
case _Refreshed() when refreshed != null:
return refreshed();case _LoadedMore() when loadedMore != null:
return loadedMore();case _:
return null;
}
}
}
/// @nodoc
class _Refreshed implements VoucherRedemptionLoaderEvent {
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 'VoucherRedemptionLoaderEvent.refreshed()';
}
}
/// @nodoc
class _LoadedMore implements VoucherRedemptionLoaderEvent {
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 'VoucherRedemptionLoaderEvent.loadedMore()';
}
}
/// @nodoc
mixin _$VoucherRedemptionLoaderState {
List<VoucherRedemption> get items; int get page; int get totalPages; Option<WalletFailure> get failureOption; bool get isFetching; bool get isLoadingMore; bool get hasLoaded;
/// Create a copy of VoucherRedemptionLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$VoucherRedemptionLoaderStateCopyWith<VoucherRedemptionLoaderState> get copyWith => _$VoucherRedemptionLoaderStateCopyWithImpl<VoucherRedemptionLoaderState>(this as VoucherRedemptionLoaderState, _$identity);
@override
bool operator ==(Object other) {
final _this = this as VoucherRedemptionLoaderState;
return identical(this, other) || (other.runtimeType == runtimeType&&other is VoucherRedemptionLoaderState&&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)&&(identical(other.hasLoaded, _this.hasLoaded) || other.hasLoaded == _this.hasLoaded));
}
@override
int get hashCode {
final _this = this as VoucherRedemptionLoaderState;
return Object.hash(runtimeType,const DeepCollectionEquality().hash(_this.items),_this.page,_this.totalPages,_this.failureOption,_this.isFetching,_this.isLoadingMore,_this.hasLoaded);
}
@override
String toString() {
final _this = this as VoucherRedemptionLoaderState;
return 'VoucherRedemptionLoaderState(items: ${_this.items}, page: ${_this.page}, totalPages: ${_this.totalPages}, failureOption: ${_this.failureOption}, isFetching: ${_this.isFetching}, isLoadingMore: ${_this.isLoadingMore}, hasLoaded: ${_this.hasLoaded})';
}
}
/// @nodoc
abstract mixin class $VoucherRedemptionLoaderStateCopyWith<$Res> {
factory $VoucherRedemptionLoaderStateCopyWith(VoucherRedemptionLoaderState value, $Res Function(VoucherRedemptionLoaderState) _then) = _$VoucherRedemptionLoaderStateCopyWithImpl;
@useResult
$Res call({
List<VoucherRedemption> items, int page, int totalPages, Option<WalletFailure> failureOption, bool isFetching, bool isLoadingMore, bool hasLoaded
});
}
/// @nodoc
class _$VoucherRedemptionLoaderStateCopyWithImpl<$Res>
implements $VoucherRedemptionLoaderStateCopyWith<$Res> {
_$VoucherRedemptionLoaderStateCopyWithImpl(this._self, this._then);
final VoucherRedemptionLoaderState _self;
final $Res Function(VoucherRedemptionLoaderState) _then;
/// Create a copy of VoucherRedemptionLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? items = null,Object? page = null,Object? totalPages = null,Object? failureOption = null,Object? isFetching = null,Object? isLoadingMore = null,Object? hasLoaded = null,}) {
return _then(VoucherRedemptionLoaderState(
items: null == items ? _self.items : items // ignore: cast_nullable_to_non_nullable
as List<VoucherRedemption>,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,hasLoaded: null == hasLoaded ? _self.hasLoaded : hasLoaded // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
/// Adds pattern-matching-related methods to [VoucherRedemptionLoaderState].
extension VoucherRedemptionLoaderStatePatterns on VoucherRedemptionLoaderState {
/// 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( _VoucherRedemptionLoaderState value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _VoucherRedemptionLoaderState() 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( _VoucherRedemptionLoaderState value) $default,){
final _that = this;
switch (_that) {
case _VoucherRedemptionLoaderState():
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( _VoucherRedemptionLoaderState value)? $default,){
final _that = this;
switch (_that) {
case _VoucherRedemptionLoaderState() 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( List<VoucherRedemption> items, int page, int totalPages, Option<WalletFailure> failureOption, bool isFetching, bool isLoadingMore, bool hasLoaded)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _VoucherRedemptionLoaderState() when $default != null:
return $default(_that.items,_that.page,_that.totalPages,_that.failureOption,_that.isFetching,_that.isLoadingMore,_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( List<VoucherRedemption> items, int page, int totalPages, Option<WalletFailure> failureOption, bool isFetching, bool isLoadingMore, bool hasLoaded) $default,) {final _that = this;
switch (_that) {
case _VoucherRedemptionLoaderState():
return $default(_that.items,_that.page,_that.totalPages,_that.failureOption,_that.isFetching,_that.isLoadingMore,_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( List<VoucherRedemption> items, int page, int totalPages, Option<WalletFailure> failureOption, bool isFetching, bool isLoadingMore, bool hasLoaded)? $default,) {final _that = this;
switch (_that) {
case _VoucherRedemptionLoaderState() when $default != null:
return $default(_that.items,_that.page,_that.totalPages,_that.failureOption,_that.isFetching,_that.isLoadingMore,_that.hasLoaded);case _:
return null;
}
}
}
/// @nodoc
class _VoucherRedemptionLoaderState extends VoucherRedemptionLoaderState {
const _VoucherRedemptionLoaderState({required List<VoucherRedemption> items, required this.page, required this.totalPages, required this.failureOption, this.isFetching = false, this.isLoadingMore = false, this.hasLoaded = false}): _items = items,super._();
final List<VoucherRedemption> _items;
@override List<VoucherRedemption> 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;
@override@JsonKey() final bool hasLoaded;
/// Create a copy of VoucherRedemptionLoaderState
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$VoucherRedemptionLoaderStateCopyWith<_VoucherRedemptionLoaderState> get copyWith => __$VoucherRedemptionLoaderStateCopyWithImpl<_VoucherRedemptionLoaderState>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _VoucherRedemptionLoaderState&&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)&&(identical(other.hasLoaded, hasLoaded) || other.hasLoaded == hasLoaded));
}
@override
int get hashCode {
return Object.hash(runtimeType,const DeepCollectionEquality().hash(_items),page,totalPages,failureOption,isFetching,isLoadingMore,hasLoaded);
}
@override
String toString() {
return 'VoucherRedemptionLoaderState(items: $items, page: $page, totalPages: $totalPages, failureOption: $failureOption, isFetching: $isFetching, isLoadingMore: $isLoadingMore, hasLoaded: $hasLoaded)';
}
}
/// @nodoc
abstract mixin class _$VoucherRedemptionLoaderStateCopyWith<$Res> implements $VoucherRedemptionLoaderStateCopyWith<$Res> {
factory _$VoucherRedemptionLoaderStateCopyWith(_VoucherRedemptionLoaderState value, $Res Function(_VoucherRedemptionLoaderState) _then) = __$VoucherRedemptionLoaderStateCopyWithImpl;
@override @useResult
$Res call({
List<VoucherRedemption> items, int page, int totalPages, Option<WalletFailure> failureOption, bool isFetching, bool isLoadingMore, bool hasLoaded
});
}
/// @nodoc
class __$VoucherRedemptionLoaderStateCopyWithImpl<$Res>
implements _$VoucherRedemptionLoaderStateCopyWith<$Res> {
__$VoucherRedemptionLoaderStateCopyWithImpl(this._self, this._then);
final _VoucherRedemptionLoaderState _self;
final $Res Function(_VoucherRedemptionLoaderState) _then;
/// Create a copy of VoucherRedemptionLoaderState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? items = null,Object? page = null,Object? totalPages = null,Object? failureOption = null,Object? isFetching = null,Object? isLoadingMore = null,Object? hasLoaded = null,}) {
return _then(_VoucherRedemptionLoaderState(
items: null == items ? _self._items : items // ignore: cast_nullable_to_non_nullable
as List<VoucherRedemption>,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,hasLoaded: null == hasLoaded ? _self.hasLoaded : hasLoaded // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
// dart format on
@@ -0,0 +1,10 @@
part of 'voucher_redemption_loader_bloc.dart';
@freezed
abstract class VoucherRedemptionLoaderEvent
with _$VoucherRedemptionLoaderEvent {
/// Muat ulang dari halaman pertama.
const factory VoucherRedemptionLoaderEvent.refreshed() = _Refreshed;
const factory VoucherRedemptionLoaderEvent.loadedMore() = _LoadedMore;
}
@@ -0,0 +1,27 @@
part of 'voucher_redemption_loader_bloc.dart';
@freezed
abstract class VoucherRedemptionLoaderState
with _$VoucherRedemptionLoaderState {
const VoucherRedemptionLoaderState._();
const factory VoucherRedemptionLoaderState({
required List<VoucherRedemption> items,
required int page,
required int totalPages,
required Option<WalletFailure> failureOption,
@Default(false) bool isFetching,
@Default(false) bool isLoadingMore,
@Default(false) bool hasLoaded,
}) = _VoucherRedemptionLoaderState;
factory VoucherRedemptionLoaderState.initial() =>
VoucherRedemptionLoaderState(
items: const [],
page: 0,
totalPages: 0,
failureOption: none(),
);
bool get hasMore => page < totalPages;
}
@@ -1,44 +0,0 @@
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)),
);
}
}
@@ -1,575 +0,0 @@
// 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
@@ -1,9 +0,0 @@
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;
}
@@ -1,13 +0,0 @@
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());
}
@@ -27,7 +27,16 @@ class WalletHistoryLoaderBloc
) {
return event.map(
currencyChanged: (e) async {
emit(state.copyWith(currency: e.currency));
// Tipe yang tidak dimiliki mata uang ini (mis. Main game di tab
// EnakPoint) dibuang dari filter.
emit(
state.copyWith(
currency: e.currency,
types: state.types
.where((type) => type.currencies.contains(e.currency))
.toList(),
),
);
await _fetchFirstPage(emit);
},
filterChanged: (e) async {
@@ -4,7 +4,8 @@ part of 'wallet_loader_bloc.dart';
abstract class WalletLoaderEvent with _$WalletLoaderEvent {
const factory WalletLoaderEvent.fetched() = _Fetched;
/// Saldo EnakCoin terbaru dari hasil main game (`coins_remaining`).
/// Saldo EnakCoin terbaru yang dikirim game lewat bridge
/// (`balance_changed`).
const factory WalletLoaderEvent.coinBalanceUpdated(int coinBalance) =
_CoinBalanceUpdated;