EnakPoint & EnakCoin wallet, PIN, outlet, order, community, reward

- Wallet EnakPoint & EnakCoin: beranda, riwayat, saldo kedaluwarsa, kode
  bayar, tukar EnakCoin, transfer
- PIN (buat, ganti, lupa), outlet, riwayat order, game spin
- Halaman community, webview, coming soon, dan ikon menu beranda baru
- Redesign Reward Saya: kartu tiket, filter chip, detail kode + QR
- Hapus customer point loader, menu, dan checkout lama
- Base URL ke enaklo-pos-api.altru.id

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
efrilm
2026-10-01 01:43:22 +07:00
co-authored by Claude Opus 5.5
parent 5954510b93
commit f5e3075205
253 changed files with 47212 additions and 17437 deletions
@@ -0,0 +1,108 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../common/function/app_function.dart';
import '../../../domain/wallet/wallet.dart';
part 'transfer_form_event.dart';
part 'transfer_form_state.dart';
part 'transfer_form_bloc.freezed.dart';
@injectable
class TransferFormBloc extends Bloc<TransferFormEvent, TransferFormState> {
final IWalletRepository _repository;
TransferFormBloc(this._repository) : super(TransferFormState.initial()) {
on<TransferFormEvent>(_onTransferFormEvent);
}
Future<void> _onTransferFormEvent(
TransferFormEvent event,
Emitter<TransferFormState> emit,
) {
return event.map(
currencyChanged: (e) async => emit(
state.copyWith(
currency: e.currency,
idempotencyKey: null,
failureOption: none(),
),
),
phoneChanged: (e) async => emit(
state.copyWith(
phone: e.phone,
recipient: null,
recipientFailureOption: none(),
idempotencyKey: null,
failureOption: none(),
),
),
amountChanged: (e) async => emit(
state.copyWith(
amount: e.amount,
idempotencyKey: null,
failureOption: none(),
),
),
recipientChecked: (e) async {
final phone = state.phone;
emit(
state.copyWith(
isCheckingRecipient: true,
recipient: null,
recipientFailureOption: none(),
),
);
final result = await _repository.checkRecipient(phone: phone);
if (state.phone != phone) return;
emit(
result
.fold(
(f) => state.copyWith(recipientFailureOption: optionOf(f)),
(recipient) => state.copyWith(recipient: recipient),
)
.copyWith(isCheckingRecipient: false),
);
},
submitted: (e) async {
// Key baru untuk setiap konfirmasi, kecuali mengulang request yang
// sebelumnya gagal karena jaringan.
final key = state.idempotencyKey ?? generateUuidV4();
emit(
state.copyWith(
isSubmitting: true,
idempotencyKey: key,
failureOption: none(),
),
);
final result = await _repository.transfer(
currency: state.currency,
amount: state.amount,
recipientPhone: state.phone,
pin: e.pin,
idempotencyKey: key,
);
emit(
result
.fold(
(f) => state.copyWith(
failureOption: optionOf(f),
idempotencyKey: f.isNetworkError ? key : null,
),
(transferResult) => state.copyWith(
result: transferResult,
idempotencyKey: null,
),
)
.copyWith(isSubmitting: false),
);
},
);
}
}
@@ -0,0 +1,842 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint, type=warning, deprecated_member_use, deprecated_member_use_from_same_package
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'transfer_form_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$TransferFormEvent {
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is TransferFormEvent);
}
@override
int get hashCode => runtimeType.hashCode;
@override
String toString() {
return 'TransferFormEvent()';
}
}
/// @nodoc
class $TransferFormEventCopyWith<$Res> {
$TransferFormEventCopyWith(TransferFormEvent _, $Res Function(TransferFormEvent) __);
}
/// Adds pattern-matching-related methods to [TransferFormEvent].
extension TransferFormEventPatterns on TransferFormEvent {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>({TResult Function( _CurrencyChanged value)? currencyChanged,TResult Function( _PhoneChanged value)? phoneChanged,TResult Function( _AmountChanged value)? amountChanged,TResult Function( _RecipientChecked value)? recipientChecked,TResult Function( _Submitted value)? submitted,required TResult orElse(),}){
final _that = this;
switch (_that) {
case _CurrencyChanged() when currencyChanged != null:
return currencyChanged(_that);case _PhoneChanged() when phoneChanged != null:
return phoneChanged(_that);case _AmountChanged() when amountChanged != null:
return amountChanged(_that);case _RecipientChecked() when recipientChecked != null:
return recipientChecked(_that);case _Submitted() when submitted != null:
return submitted(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>({required TResult Function( _CurrencyChanged value) currencyChanged,required TResult Function( _PhoneChanged value) phoneChanged,required TResult Function( _AmountChanged value) amountChanged,required TResult Function( _RecipientChecked value) recipientChecked,required TResult Function( _Submitted value) submitted,}){
final _that = this;
switch (_that) {
case _CurrencyChanged():
return currencyChanged(_that);case _PhoneChanged():
return phoneChanged(_that);case _AmountChanged():
return amountChanged(_that);case _RecipientChecked():
return recipientChecked(_that);case _Submitted():
return submitted(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>({TResult? Function( _CurrencyChanged value)? currencyChanged,TResult? Function( _PhoneChanged value)? phoneChanged,TResult? Function( _AmountChanged value)? amountChanged,TResult? Function( _RecipientChecked value)? recipientChecked,TResult? Function( _Submitted value)? submitted,}){
final _that = this;
switch (_that) {
case _CurrencyChanged() when currencyChanged != null:
return currencyChanged(_that);case _PhoneChanged() when phoneChanged != null:
return phoneChanged(_that);case _AmountChanged() when amountChanged != null:
return amountChanged(_that);case _RecipientChecked() when recipientChecked != null:
return recipientChecked(_that);case _Submitted() when submitted != null:
return submitted(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function( WalletCurrency currency)? currencyChanged,TResult Function( String phone)? phoneChanged,TResult Function( int amount)? amountChanged,TResult Function()? recipientChecked,TResult Function( String pin)? submitted,required TResult orElse(),}) {final _that = this;
switch (_that) {
case _CurrencyChanged() when currencyChanged != null:
return currencyChanged(_that.currency);case _PhoneChanged() when phoneChanged != null:
return phoneChanged(_that.phone);case _AmountChanged() when amountChanged != null:
return amountChanged(_that.amount);case _RecipientChecked() when recipientChecked != null:
return recipientChecked();case _Submitted() when submitted != null:
return submitted(_that.pin);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function( WalletCurrency currency) currencyChanged,required TResult Function( String phone) phoneChanged,required TResult Function( int amount) amountChanged,required TResult Function() recipientChecked,required TResult Function( String pin) submitted,}) {final _that = this;
switch (_that) {
case _CurrencyChanged():
return currencyChanged(_that.currency);case _PhoneChanged():
return phoneChanged(_that.phone);case _AmountChanged():
return amountChanged(_that.amount);case _RecipientChecked():
return recipientChecked();case _Submitted():
return submitted(_that.pin);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult? Function( WalletCurrency currency)? currencyChanged,TResult? Function( String phone)? phoneChanged,TResult? Function( int amount)? amountChanged,TResult? Function()? recipientChecked,TResult? Function( String pin)? submitted,}) {final _that = this;
switch (_that) {
case _CurrencyChanged() when currencyChanged != null:
return currencyChanged(_that.currency);case _PhoneChanged() when phoneChanged != null:
return phoneChanged(_that.phone);case _AmountChanged() when amountChanged != null:
return amountChanged(_that.amount);case _RecipientChecked() when recipientChecked != null:
return recipientChecked();case _Submitted() when submitted != null:
return submitted(_that.pin);case _:
return null;
}
}
}
/// @nodoc
class _CurrencyChanged implements TransferFormEvent {
const _CurrencyChanged(this.currency);
final WalletCurrency currency;
/// Create a copy of TransferFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$CurrencyChangedCopyWith<_CurrencyChanged> get copyWith => __$CurrencyChangedCopyWithImpl<_CurrencyChanged>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _CurrencyChanged&&(identical(other.currency, currency) || other.currency == currency));
}
@override
int get hashCode {
return Object.hash(runtimeType,currency);
}
@override
String toString() {
return 'TransferFormEvent.currencyChanged(currency: $currency)';
}
}
/// @nodoc
abstract mixin class _$CurrencyChangedCopyWith<$Res> implements $TransferFormEventCopyWith<$Res> {
factory _$CurrencyChangedCopyWith(_CurrencyChanged value, $Res Function(_CurrencyChanged) _then) = __$CurrencyChangedCopyWithImpl;
@useResult
$Res call({
WalletCurrency currency
});
}
/// @nodoc
class __$CurrencyChangedCopyWithImpl<$Res>
implements _$CurrencyChangedCopyWith<$Res> {
__$CurrencyChangedCopyWithImpl(this._self, this._then);
final _CurrencyChanged _self;
final $Res Function(_CurrencyChanged) _then;
/// Create a copy of TransferFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') $Res call({Object? currency = null,}) {
return _then(_CurrencyChanged(
null == currency ? _self.currency : currency // ignore: cast_nullable_to_non_nullable
as WalletCurrency,
));
}
}
/// @nodoc
class _PhoneChanged implements TransferFormEvent {
const _PhoneChanged(this.phone);
final String phone;
/// Create a copy of TransferFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$PhoneChangedCopyWith<_PhoneChanged> get copyWith => __$PhoneChangedCopyWithImpl<_PhoneChanged>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _PhoneChanged&&(identical(other.phone, phone) || other.phone == phone));
}
@override
int get hashCode {
return Object.hash(runtimeType,phone);
}
@override
String toString() {
return 'TransferFormEvent.phoneChanged(phone: $phone)';
}
}
/// @nodoc
abstract mixin class _$PhoneChangedCopyWith<$Res> implements $TransferFormEventCopyWith<$Res> {
factory _$PhoneChangedCopyWith(_PhoneChanged value, $Res Function(_PhoneChanged) _then) = __$PhoneChangedCopyWithImpl;
@useResult
$Res call({
String phone
});
}
/// @nodoc
class __$PhoneChangedCopyWithImpl<$Res>
implements _$PhoneChangedCopyWith<$Res> {
__$PhoneChangedCopyWithImpl(this._self, this._then);
final _PhoneChanged _self;
final $Res Function(_PhoneChanged) _then;
/// Create a copy of TransferFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') $Res call({Object? phone = null,}) {
return _then(_PhoneChanged(
null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _AmountChanged implements TransferFormEvent {
const _AmountChanged(this.amount);
final int amount;
/// Create a copy of TransferFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$AmountChangedCopyWith<_AmountChanged> get copyWith => __$AmountChangedCopyWithImpl<_AmountChanged>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _AmountChanged&&(identical(other.amount, amount) || other.amount == amount));
}
@override
int get hashCode {
return Object.hash(runtimeType,amount);
}
@override
String toString() {
return 'TransferFormEvent.amountChanged(amount: $amount)';
}
}
/// @nodoc
abstract mixin class _$AmountChangedCopyWith<$Res> implements $TransferFormEventCopyWith<$Res> {
factory _$AmountChangedCopyWith(_AmountChanged value, $Res Function(_AmountChanged) _then) = __$AmountChangedCopyWithImpl;
@useResult
$Res call({
int amount
});
}
/// @nodoc
class __$AmountChangedCopyWithImpl<$Res>
implements _$AmountChangedCopyWith<$Res> {
__$AmountChangedCopyWithImpl(this._self, this._then);
final _AmountChanged _self;
final $Res Function(_AmountChanged) _then;
/// Create a copy of TransferFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') $Res call({Object? amount = null,}) {
return _then(_AmountChanged(
null == amount ? _self.amount : amount // ignore: cast_nullable_to_non_nullable
as int,
));
}
}
/// @nodoc
class _RecipientChecked implements TransferFormEvent {
const _RecipientChecked();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _RecipientChecked);
}
@override
int get hashCode => runtimeType.hashCode;
@override
String toString() {
return 'TransferFormEvent.recipientChecked()';
}
}
/// @nodoc
class _Submitted implements TransferFormEvent {
const _Submitted(this.pin);
final String pin;
/// Create a copy of TransferFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$SubmittedCopyWith<_Submitted> get copyWith => __$SubmittedCopyWithImpl<_Submitted>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Submitted&&(identical(other.pin, pin) || other.pin == pin));
}
@override
int get hashCode {
return Object.hash(runtimeType,pin);
}
@override
String toString() {
return 'TransferFormEvent.submitted(pin: $pin)';
}
}
/// @nodoc
abstract mixin class _$SubmittedCopyWith<$Res> implements $TransferFormEventCopyWith<$Res> {
factory _$SubmittedCopyWith(_Submitted value, $Res Function(_Submitted) _then) = __$SubmittedCopyWithImpl;
@useResult
$Res call({
String pin
});
}
/// @nodoc
class __$SubmittedCopyWithImpl<$Res>
implements _$SubmittedCopyWith<$Res> {
__$SubmittedCopyWithImpl(this._self, this._then);
final _Submitted _self;
final $Res Function(_Submitted) _then;
/// Create a copy of TransferFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') $Res call({Object? pin = null,}) {
return _then(_Submitted(
null == pin ? _self.pin : pin // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
mixin _$TransferFormState {
WalletCurrency get currency; String get phone; int get amount; TransferRecipient? get recipient; Option<WalletFailure> get recipientFailureOption; bool get isCheckingRecipient; TransferResult? get result; Option<WalletFailure> get failureOption; bool get isSubmitting; String? get idempotencyKey;
/// Create a copy of TransferFormState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$TransferFormStateCopyWith<TransferFormState> get copyWith => _$TransferFormStateCopyWithImpl<TransferFormState>(this as TransferFormState, _$identity);
@override
bool operator ==(Object other) {
final _this = this as TransferFormState;
return identical(this, other) || (other.runtimeType == runtimeType&&other is TransferFormState&&(identical(other.currency, _this.currency) || other.currency == _this.currency)&&(identical(other.phone, _this.phone) || other.phone == _this.phone)&&(identical(other.amount, _this.amount) || other.amount == _this.amount)&&(identical(other.recipient, _this.recipient) || other.recipient == _this.recipient)&&(identical(other.recipientFailureOption, _this.recipientFailureOption) || other.recipientFailureOption == _this.recipientFailureOption)&&(identical(other.isCheckingRecipient, _this.isCheckingRecipient) || other.isCheckingRecipient == _this.isCheckingRecipient)&&(identical(other.result, _this.result) || other.result == _this.result)&&(identical(other.failureOption, _this.failureOption) || other.failureOption == _this.failureOption)&&(identical(other.isSubmitting, _this.isSubmitting) || other.isSubmitting == _this.isSubmitting)&&(identical(other.idempotencyKey, _this.idempotencyKey) || other.idempotencyKey == _this.idempotencyKey));
}
@override
int get hashCode {
final _this = this as TransferFormState;
return Object.hash(runtimeType,_this.currency,_this.phone,_this.amount,_this.recipient,_this.recipientFailureOption,_this.isCheckingRecipient,_this.result,_this.failureOption,_this.isSubmitting,_this.idempotencyKey);
}
@override
String toString() {
final _this = this as TransferFormState;
return 'TransferFormState(currency: ${_this.currency}, phone: ${_this.phone}, amount: ${_this.amount}, recipient: ${_this.recipient}, recipientFailureOption: ${_this.recipientFailureOption}, isCheckingRecipient: ${_this.isCheckingRecipient}, result: ${_this.result}, failureOption: ${_this.failureOption}, isSubmitting: ${_this.isSubmitting}, idempotencyKey: ${_this.idempotencyKey})';
}
}
/// @nodoc
abstract mixin class $TransferFormStateCopyWith<$Res> {
factory $TransferFormStateCopyWith(TransferFormState value, $Res Function(TransferFormState) _then) = _$TransferFormStateCopyWithImpl;
@useResult
$Res call({
WalletCurrency currency, String phone, int amount, TransferRecipient? recipient, Option<WalletFailure> recipientFailureOption, bool isCheckingRecipient, TransferResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey
});
$TransferRecipientCopyWith<$Res>? get recipient;$TransferResultCopyWith<$Res>? get result;
}
/// @nodoc
class _$TransferFormStateCopyWithImpl<$Res>
implements $TransferFormStateCopyWith<$Res> {
_$TransferFormStateCopyWithImpl(this._self, this._then);
final TransferFormState _self;
final $Res Function(TransferFormState) _then;
/// Create a copy of TransferFormState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? currency = null,Object? phone = null,Object? amount = null,Object? recipient = freezed,Object? recipientFailureOption = null,Object? isCheckingRecipient = null,Object? result = freezed,Object? failureOption = null,Object? isSubmitting = null,Object? idempotencyKey = freezed,}) {
return _then(TransferFormState(
currency: null == currency ? _self.currency : currency // ignore: cast_nullable_to_non_nullable
as WalletCurrency,phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
as String,amount: null == amount ? _self.amount : amount // ignore: cast_nullable_to_non_nullable
as int,recipient: freezed == recipient ? _self.recipient : recipient // ignore: cast_nullable_to_non_nullable
as TransferRecipient?,recipientFailureOption: null == recipientFailureOption ? _self.recipientFailureOption : recipientFailureOption // ignore: cast_nullable_to_non_nullable
as Option<WalletFailure>,isCheckingRecipient: null == isCheckingRecipient ? _self.isCheckingRecipient : isCheckingRecipient // ignore: cast_nullable_to_non_nullable
as bool,result: freezed == result ? _self.result : result // ignore: cast_nullable_to_non_nullable
as TransferResult?,failureOption: null == failureOption ? _self.failureOption : failureOption // ignore: cast_nullable_to_non_nullable
as Option<WalletFailure>,isSubmitting: null == isSubmitting ? _self.isSubmitting : isSubmitting // ignore: cast_nullable_to_non_nullable
as bool,idempotencyKey: freezed == idempotencyKey ? _self.idempotencyKey : idempotencyKey // ignore: cast_nullable_to_non_nullable
as String?,
));
}
/// Create a copy of TransferFormState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$TransferRecipientCopyWith<$Res>? get recipient {
if (_self.recipient == null) {
return null;
}
return $TransferRecipientCopyWith<$Res>(_self.recipient!, (value) {
return _then(_self.copyWith(recipient: value));
});
}/// Create a copy of TransferFormState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$TransferResultCopyWith<$Res>? get result {
if (_self.result == null) {
return null;
}
return $TransferResultCopyWith<$Res>(_self.result!, (value) {
return _then(_self.copyWith(result: value));
});
}
}
/// Adds pattern-matching-related methods to [TransferFormState].
extension TransferFormStatePatterns on TransferFormState {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _TransferFormState value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _TransferFormState() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _TransferFormState value) $default,){
final _that = this;
switch (_that) {
case _TransferFormState():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _TransferFormState value)? $default,){
final _that = this;
switch (_that) {
case _TransferFormState() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( WalletCurrency currency, String phone, int amount, TransferRecipient? recipient, Option<WalletFailure> recipientFailureOption, bool isCheckingRecipient, TransferResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _TransferFormState() when $default != null:
return $default(_that.currency,_that.phone,_that.amount,_that.recipient,_that.recipientFailureOption,_that.isCheckingRecipient,_that.result,_that.failureOption,_that.isSubmitting,_that.idempotencyKey);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( WalletCurrency currency, String phone, int amount, TransferRecipient? recipient, Option<WalletFailure> recipientFailureOption, bool isCheckingRecipient, TransferResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey) $default,) {final _that = this;
switch (_that) {
case _TransferFormState():
return $default(_that.currency,_that.phone,_that.amount,_that.recipient,_that.recipientFailureOption,_that.isCheckingRecipient,_that.result,_that.failureOption,_that.isSubmitting,_that.idempotencyKey);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( WalletCurrency currency, String phone, int amount, TransferRecipient? recipient, Option<WalletFailure> recipientFailureOption, bool isCheckingRecipient, TransferResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey)? $default,) {final _that = this;
switch (_that) {
case _TransferFormState() when $default != null:
return $default(_that.currency,_that.phone,_that.amount,_that.recipient,_that.recipientFailureOption,_that.isCheckingRecipient,_that.result,_that.failureOption,_that.isSubmitting,_that.idempotencyKey);case _:
return null;
}
}
}
/// @nodoc
class _TransferFormState extends TransferFormState {
const _TransferFormState({required this.currency, required this.phone, required this.amount, this.recipient, required this.recipientFailureOption, this.isCheckingRecipient = false, this.result, required this.failureOption, this.isSubmitting = false, this.idempotencyKey}): super._();
@override final WalletCurrency currency;
@override final String phone;
@override final int amount;
@override final TransferRecipient? recipient;
@override final Option<WalletFailure> recipientFailureOption;
@override@JsonKey() final bool isCheckingRecipient;
@override final TransferResult? result;
@override final Option<WalletFailure> failureOption;
@override@JsonKey() final bool isSubmitting;
@override final String? idempotencyKey;
/// Create a copy of TransferFormState
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$TransferFormStateCopyWith<_TransferFormState> get copyWith => __$TransferFormStateCopyWithImpl<_TransferFormState>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _TransferFormState&&(identical(other.currency, currency) || other.currency == currency)&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.amount, amount) || other.amount == amount)&&(identical(other.recipient, recipient) || other.recipient == recipient)&&(identical(other.recipientFailureOption, recipientFailureOption) || other.recipientFailureOption == recipientFailureOption)&&(identical(other.isCheckingRecipient, isCheckingRecipient) || other.isCheckingRecipient == isCheckingRecipient)&&(identical(other.result, result) || other.result == result)&&(identical(other.failureOption, failureOption) || other.failureOption == failureOption)&&(identical(other.isSubmitting, isSubmitting) || other.isSubmitting == isSubmitting)&&(identical(other.idempotencyKey, idempotencyKey) || other.idempotencyKey == idempotencyKey));
}
@override
int get hashCode {
return Object.hash(runtimeType,currency,phone,amount,recipient,recipientFailureOption,isCheckingRecipient,result,failureOption,isSubmitting,idempotencyKey);
}
@override
String toString() {
return 'TransferFormState(currency: $currency, phone: $phone, amount: $amount, recipient: $recipient, recipientFailureOption: $recipientFailureOption, isCheckingRecipient: $isCheckingRecipient, result: $result, failureOption: $failureOption, isSubmitting: $isSubmitting, idempotencyKey: $idempotencyKey)';
}
}
/// @nodoc
abstract mixin class _$TransferFormStateCopyWith<$Res> implements $TransferFormStateCopyWith<$Res> {
factory _$TransferFormStateCopyWith(_TransferFormState value, $Res Function(_TransferFormState) _then) = __$TransferFormStateCopyWithImpl;
@override @useResult
$Res call({
WalletCurrency currency, String phone, int amount, TransferRecipient? recipient, Option<WalletFailure> recipientFailureOption, bool isCheckingRecipient, TransferResult? result, Option<WalletFailure> failureOption, bool isSubmitting, String? idempotencyKey
});
@override $TransferRecipientCopyWith<$Res>? get recipient;@override $TransferResultCopyWith<$Res>? get result;
}
/// @nodoc
class __$TransferFormStateCopyWithImpl<$Res>
implements _$TransferFormStateCopyWith<$Res> {
__$TransferFormStateCopyWithImpl(this._self, this._then);
final _TransferFormState _self;
final $Res Function(_TransferFormState) _then;
/// Create a copy of TransferFormState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? currency = null,Object? phone = null,Object? amount = null,Object? recipient = freezed,Object? recipientFailureOption = null,Object? isCheckingRecipient = null,Object? result = freezed,Object? failureOption = null,Object? isSubmitting = null,Object? idempotencyKey = freezed,}) {
return _then(_TransferFormState(
currency: null == currency ? _self.currency : currency // ignore: cast_nullable_to_non_nullable
as WalletCurrency,phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
as String,amount: null == amount ? _self.amount : amount // ignore: cast_nullable_to_non_nullable
as int,recipient: freezed == recipient ? _self.recipient : recipient // ignore: cast_nullable_to_non_nullable
as TransferRecipient?,recipientFailureOption: null == recipientFailureOption ? _self.recipientFailureOption : recipientFailureOption // ignore: cast_nullable_to_non_nullable
as Option<WalletFailure>,isCheckingRecipient: null == isCheckingRecipient ? _self.isCheckingRecipient : isCheckingRecipient // ignore: cast_nullable_to_non_nullable
as bool,result: freezed == result ? _self.result : result // ignore: cast_nullable_to_non_nullable
as TransferResult?,failureOption: null == failureOption ? _self.failureOption : failureOption // ignore: cast_nullable_to_non_nullable
as Option<WalletFailure>,isSubmitting: null == isSubmitting ? _self.isSubmitting : isSubmitting // ignore: cast_nullable_to_non_nullable
as bool,idempotencyKey: freezed == idempotencyKey ? _self.idempotencyKey : idempotencyKey // ignore: cast_nullable_to_non_nullable
as String?,
));
}
/// Create a copy of TransferFormState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$TransferRecipientCopyWith<$Res>? get recipient {
if (_self.recipient == null) {
return null;
}
return $TransferRecipientCopyWith<$Res>(_self.recipient!, (value) {
return _then(_self.copyWith(recipient: value));
});
}/// Create a copy of TransferFormState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$TransferResultCopyWith<$Res>? get result {
if (_self.result == null) {
return null;
}
return $TransferResultCopyWith<$Res>(_self.result!, (value) {
return _then(_self.copyWith(result: value));
});
}
}
// dart format on
@@ -0,0 +1,16 @@
part of 'transfer_form_bloc.dart';
@freezed
abstract class TransferFormEvent with _$TransferFormEvent {
const factory TransferFormEvent.currencyChanged(WalletCurrency currency) =
_CurrencyChanged;
const factory TransferFormEvent.phoneChanged(String phone) = _PhoneChanged;
const factory TransferFormEvent.amountChanged(int amount) = _AmountChanged;
const factory TransferFormEvent.recipientChecked() = _RecipientChecked;
/// [pin] hanya diteruskan ke API, tidak disimpan di state.
const factory TransferFormEvent.submitted(String pin) = _Submitted;
}
@@ -0,0 +1,29 @@
part of 'transfer_form_bloc.dart';
@freezed
abstract class TransferFormState with _$TransferFormState {
const TransferFormState._();
const factory TransferFormState({
required WalletCurrency currency,
required String phone,
required int amount,
TransferRecipient? recipient,
required Option<WalletFailure> recipientFailureOption,
@Default(false) bool isCheckingRecipient,
TransferResult? result,
required Option<WalletFailure> failureOption,
@Default(false) bool isSubmitting,
String? idempotencyKey,
}) = _TransferFormState;
factory TransferFormState.initial() => TransferFormState(
currency: WalletCurrency.point,
phone: '',
amount: 0,
recipientFailureOption: none(),
failureOption: none(),
);
bool get isFilled => phone.length >= 9 && amount > 0;
}