EnakPoint & EnakCoin wallet, PIN, outlet, order, community, reward
- Wallet EnakPoint & EnakCoin: beranda, riwayat, saldo kedaluwarsa, kode bayar, tukar EnakCoin, transfer - PIN (buat, ganti, lupa), outlet, riwayat order, game spin - Halaman community, webview, coming soon, dan ikon menu beranda baru - Redesign Reward Saya: kartu tiket, filter chip, detail kode + QR - Hapus customer point loader, menu, dan checkout lama - Base URL ke enaklo-pos-api.altru.id Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5954510b93
commit
f5e3075205
@@ -0,0 +1,86 @@
|
||||
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 'pin_setup_form_event.dart';
|
||||
part 'pin_setup_form_state.dart';
|
||||
part 'pin_setup_form_bloc.freezed.dart';
|
||||
|
||||
/// Alur buat PIN (`pin_setup`) dan lupa PIN (`pin_reset`) lewat OTP WhatsApp.
|
||||
@injectable
|
||||
class PinSetupFormBloc extends Bloc<PinSetupFormEvent, PinSetupFormState> {
|
||||
final IPinRepository _repository;
|
||||
|
||||
PinSetupFormBloc(this._repository) : super(PinSetupFormState.initial()) {
|
||||
on<PinSetupFormEvent>(_onPinSetupFormEvent);
|
||||
}
|
||||
|
||||
Future<void> _onPinSetupFormEvent(
|
||||
PinSetupFormEvent event,
|
||||
Emitter<PinSetupFormState> emit,
|
||||
) {
|
||||
return event.map(
|
||||
otpRequested: (e) async {
|
||||
emit(
|
||||
state.copyWith(
|
||||
purpose: e.purpose,
|
||||
isRequestingOtp: true,
|
||||
otpFailureOption: none(),
|
||||
),
|
||||
);
|
||||
|
||||
final result = await _repository.requestOtp(e.purpose);
|
||||
|
||||
emit(
|
||||
result
|
||||
.fold(
|
||||
(f) => state.copyWith(
|
||||
otpFailureOption: optionOf(f),
|
||||
resendAvailableAt: f.maybeMap(
|
||||
tooManyRequests: (value) => DateTime.now().add(
|
||||
Duration(seconds: value.retryAfterSeconds),
|
||||
),
|
||||
orElse: () => state.resendAvailableAt,
|
||||
),
|
||||
),
|
||||
(otp) => state.copyWith(otp: otp),
|
||||
)
|
||||
.copyWith(isRequestingOtp: false),
|
||||
);
|
||||
},
|
||||
submitted: (e) async {
|
||||
final otp = state.otp;
|
||||
if (otp == null) return;
|
||||
|
||||
emit(
|
||||
state.copyWith(isSubmitting: true, failureOrSuccessOption: none()),
|
||||
);
|
||||
|
||||
final Either<WalletFailure, Unit> result =
|
||||
state.purpose == PinOtpPurpose.setup
|
||||
? (await _repository.setup(
|
||||
otpToken: otp.otpToken,
|
||||
otpCode: e.otpCode,
|
||||
pin: e.pin,
|
||||
confirmPin: e.confirmPin,
|
||||
)).map((_) => unit)
|
||||
: await _repository.reset(
|
||||
otpToken: otp.otpToken,
|
||||
otpCode: e.otpCode,
|
||||
pin: e.pin,
|
||||
confirmPin: e.confirmPin,
|
||||
);
|
||||
|
||||
emit(
|
||||
state.copyWith(
|
||||
isSubmitting: false,
|
||||
failureOrSuccessOption: optionOf(result),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,631 @@
|
||||
// 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 'pin_setup_form_bloc.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$PinSetupFormEvent {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is PinSetupFormEvent);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PinSetupFormEvent()';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class $PinSetupFormEventCopyWith<$Res> {
|
||||
$PinSetupFormEventCopyWith(PinSetupFormEvent _, $Res Function(PinSetupFormEvent) __);
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [PinSetupFormEvent].
|
||||
extension PinSetupFormEventPatterns on PinSetupFormEvent {
|
||||
/// 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( _OtpRequested value)? otpRequested,TResult Function( _Submitted value)? submitted,required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _OtpRequested() when otpRequested != null:
|
||||
return otpRequested(_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( _OtpRequested value) otpRequested,required TResult Function( _Submitted value) submitted,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _OtpRequested():
|
||||
return otpRequested(_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( _OtpRequested value)? otpRequested,TResult? Function( _Submitted value)? submitted,}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _OtpRequested() when otpRequested != null:
|
||||
return otpRequested(_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( PinOtpPurpose purpose)? otpRequested,TResult Function( String otpCode, String pin, String confirmPin)? submitted,required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _OtpRequested() when otpRequested != null:
|
||||
return otpRequested(_that.purpose);case _Submitted() when submitted != null:
|
||||
return submitted(_that.otpCode,_that.pin,_that.confirmPin);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( PinOtpPurpose purpose) otpRequested,required TResult Function( String otpCode, String pin, String confirmPin) submitted,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _OtpRequested():
|
||||
return otpRequested(_that.purpose);case _Submitted():
|
||||
return submitted(_that.otpCode,_that.pin,_that.confirmPin);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( PinOtpPurpose purpose)? otpRequested,TResult? Function( String otpCode, String pin, String confirmPin)? submitted,}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _OtpRequested() when otpRequested != null:
|
||||
return otpRequested(_that.purpose);case _Submitted() when submitted != null:
|
||||
return submitted(_that.otpCode,_that.pin,_that.confirmPin);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _OtpRequested implements PinSetupFormEvent {
|
||||
const _OtpRequested(this.purpose);
|
||||
|
||||
|
||||
final PinOtpPurpose purpose;
|
||||
|
||||
/// Create a copy of PinSetupFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$OtpRequestedCopyWith<_OtpRequested> get copyWith => __$OtpRequestedCopyWithImpl<_OtpRequested>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _OtpRequested&&(identical(other.purpose, purpose) || other.purpose == purpose));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,purpose);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PinSetupFormEvent.otpRequested(purpose: $purpose)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$OtpRequestedCopyWith<$Res> implements $PinSetupFormEventCopyWith<$Res> {
|
||||
factory _$OtpRequestedCopyWith(_OtpRequested value, $Res Function(_OtpRequested) _then) = __$OtpRequestedCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
PinOtpPurpose purpose
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$OtpRequestedCopyWithImpl<$Res>
|
||||
implements _$OtpRequestedCopyWith<$Res> {
|
||||
__$OtpRequestedCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _OtpRequested _self;
|
||||
final $Res Function(_OtpRequested) _then;
|
||||
|
||||
/// Create a copy of PinSetupFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? purpose = null,}) {
|
||||
return _then(_OtpRequested(
|
||||
null == purpose ? _self.purpose : purpose // ignore: cast_nullable_to_non_nullable
|
||||
as PinOtpPurpose,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _Submitted implements PinSetupFormEvent {
|
||||
const _Submitted({required this.otpCode, required this.pin, required this.confirmPin});
|
||||
|
||||
|
||||
final String otpCode;
|
||||
final String pin;
|
||||
final String confirmPin;
|
||||
|
||||
/// Create a copy of PinSetupFormEvent
|
||||
/// 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.otpCode, otpCode) || other.otpCode == otpCode)&&(identical(other.pin, pin) || other.pin == pin)&&(identical(other.confirmPin, confirmPin) || other.confirmPin == confirmPin));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,otpCode,pin,confirmPin);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PinSetupFormEvent.submitted(otpCode: $otpCode, pin: $pin, confirmPin: $confirmPin)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$SubmittedCopyWith<$Res> implements $PinSetupFormEventCopyWith<$Res> {
|
||||
factory _$SubmittedCopyWith(_Submitted value, $Res Function(_Submitted) _then) = __$SubmittedCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String otpCode, String pin, String confirmPin
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$SubmittedCopyWithImpl<$Res>
|
||||
implements _$SubmittedCopyWith<$Res> {
|
||||
__$SubmittedCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _Submitted _self;
|
||||
final $Res Function(_Submitted) _then;
|
||||
|
||||
/// Create a copy of PinSetupFormEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') $Res call({Object? otpCode = null,Object? pin = null,Object? confirmPin = null,}) {
|
||||
return _then(_Submitted(
|
||||
otpCode: null == otpCode ? _self.otpCode : otpCode // ignore: cast_nullable_to_non_nullable
|
||||
as String,pin: null == pin ? _self.pin : pin // ignore: cast_nullable_to_non_nullable
|
||||
as String,confirmPin: null == confirmPin ? _self.confirmPin : confirmPin // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$PinSetupFormState {
|
||||
|
||||
PinOtpPurpose get purpose; PinOtp? get otp; bool get isRequestingOtp; Option<WalletFailure> get otpFailureOption;/// Diisi saat server menjawab `429`; tombol kirim ulang menunggu sampai
|
||||
/// waktu ini.
|
||||
DateTime? get resendAvailableAt; bool get isSubmitting; Option<Either<WalletFailure, Unit>> get failureOrSuccessOption;
|
||||
/// Create a copy of PinSetupFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$PinSetupFormStateCopyWith<PinSetupFormState> get copyWith => _$PinSetupFormStateCopyWithImpl<PinSetupFormState>(this as PinSetupFormState, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
final _this = this as PinSetupFormState;
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is PinSetupFormState&&(identical(other.purpose, _this.purpose) || other.purpose == _this.purpose)&&(identical(other.otp, _this.otp) || other.otp == _this.otp)&&(identical(other.isRequestingOtp, _this.isRequestingOtp) || other.isRequestingOtp == _this.isRequestingOtp)&&(identical(other.otpFailureOption, _this.otpFailureOption) || other.otpFailureOption == _this.otpFailureOption)&&(identical(other.resendAvailableAt, _this.resendAvailableAt) || other.resendAvailableAt == _this.resendAvailableAt)&&(identical(other.isSubmitting, _this.isSubmitting) || other.isSubmitting == _this.isSubmitting)&&(identical(other.failureOrSuccessOption, _this.failureOrSuccessOption) || other.failureOrSuccessOption == _this.failureOrSuccessOption));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as PinSetupFormState;
|
||||
return Object.hash(runtimeType,_this.purpose,_this.otp,_this.isRequestingOtp,_this.otpFailureOption,_this.resendAvailableAt,_this.isSubmitting,_this.failureOrSuccessOption);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as PinSetupFormState;
|
||||
return 'PinSetupFormState(purpose: ${_this.purpose}, otp: ${_this.otp}, isRequestingOtp: ${_this.isRequestingOtp}, otpFailureOption: ${_this.otpFailureOption}, resendAvailableAt: ${_this.resendAvailableAt}, isSubmitting: ${_this.isSubmitting}, failureOrSuccessOption: ${_this.failureOrSuccessOption})';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $PinSetupFormStateCopyWith<$Res> {
|
||||
factory $PinSetupFormStateCopyWith(PinSetupFormState value, $Res Function(PinSetupFormState) _then) = _$PinSetupFormStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
PinOtpPurpose purpose, PinOtp? otp, bool isRequestingOtp, Option<WalletFailure> otpFailureOption, DateTime? resendAvailableAt, bool isSubmitting, Option<Either<WalletFailure, Unit>> failureOrSuccessOption
|
||||
});
|
||||
|
||||
|
||||
$PinOtpCopyWith<$Res>? get otp;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$PinSetupFormStateCopyWithImpl<$Res>
|
||||
implements $PinSetupFormStateCopyWith<$Res> {
|
||||
_$PinSetupFormStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final PinSetupFormState _self;
|
||||
final $Res Function(PinSetupFormState) _then;
|
||||
|
||||
/// Create a copy of PinSetupFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? purpose = null,Object? otp = freezed,Object? isRequestingOtp = null,Object? otpFailureOption = null,Object? resendAvailableAt = freezed,Object? isSubmitting = null,Object? failureOrSuccessOption = null,}) {
|
||||
return _then(PinSetupFormState(
|
||||
purpose: null == purpose ? _self.purpose : purpose // ignore: cast_nullable_to_non_nullable
|
||||
as PinOtpPurpose,otp: freezed == otp ? _self.otp : otp // ignore: cast_nullable_to_non_nullable
|
||||
as PinOtp?,isRequestingOtp: null == isRequestingOtp ? _self.isRequestingOtp : isRequestingOtp // ignore: cast_nullable_to_non_nullable
|
||||
as bool,otpFailureOption: null == otpFailureOption ? _self.otpFailureOption : otpFailureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,resendAvailableAt: freezed == resendAvailableAt ? _self.resendAvailableAt : resendAvailableAt // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,isSubmitting: null == isSubmitting ? _self.isSubmitting : isSubmitting // ignore: cast_nullable_to_non_nullable
|
||||
as bool,failureOrSuccessOption: null == failureOrSuccessOption ? _self.failureOrSuccessOption : failureOrSuccessOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<Either<WalletFailure, Unit>>,
|
||||
));
|
||||
}
|
||||
/// Create a copy of PinSetupFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$PinOtpCopyWith<$Res>? get otp {
|
||||
if (_self.otp == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $PinOtpCopyWith<$Res>(_self.otp!, (value) {
|
||||
return _then(_self.copyWith(otp: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [PinSetupFormState].
|
||||
extension PinSetupFormStatePatterns on PinSetupFormState {
|
||||
/// 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( _PinSetupFormState value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _PinSetupFormState() 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( _PinSetupFormState value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _PinSetupFormState():
|
||||
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( _PinSetupFormState value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _PinSetupFormState() 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( PinOtpPurpose purpose, PinOtp? otp, bool isRequestingOtp, Option<WalletFailure> otpFailureOption, DateTime? resendAvailableAt, bool isSubmitting, Option<Either<WalletFailure, Unit>> failureOrSuccessOption)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _PinSetupFormState() when $default != null:
|
||||
return $default(_that.purpose,_that.otp,_that.isRequestingOtp,_that.otpFailureOption,_that.resendAvailableAt,_that.isSubmitting,_that.failureOrSuccessOption);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( PinOtpPurpose purpose, PinOtp? otp, bool isRequestingOtp, Option<WalletFailure> otpFailureOption, DateTime? resendAvailableAt, bool isSubmitting, Option<Either<WalletFailure, Unit>> failureOrSuccessOption) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _PinSetupFormState():
|
||||
return $default(_that.purpose,_that.otp,_that.isRequestingOtp,_that.otpFailureOption,_that.resendAvailableAt,_that.isSubmitting,_that.failureOrSuccessOption);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( PinOtpPurpose purpose, PinOtp? otp, bool isRequestingOtp, Option<WalletFailure> otpFailureOption, DateTime? resendAvailableAt, bool isSubmitting, Option<Either<WalletFailure, Unit>> failureOrSuccessOption)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _PinSetupFormState() when $default != null:
|
||||
return $default(_that.purpose,_that.otp,_that.isRequestingOtp,_that.otpFailureOption,_that.resendAvailableAt,_that.isSubmitting,_that.failureOrSuccessOption);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _PinSetupFormState implements PinSetupFormState {
|
||||
const _PinSetupFormState({required this.purpose, this.otp, this.isRequestingOtp = false, required this.otpFailureOption, this.resendAvailableAt, this.isSubmitting = false, required this.failureOrSuccessOption});
|
||||
|
||||
|
||||
@override final PinOtpPurpose purpose;
|
||||
@override final PinOtp? otp;
|
||||
@override@JsonKey() final bool isRequestingOtp;
|
||||
@override final Option<WalletFailure> otpFailureOption;
|
||||
/// Diisi saat server menjawab `429`; tombol kirim ulang menunggu sampai
|
||||
/// waktu ini.
|
||||
@override final DateTime? resendAvailableAt;
|
||||
@override@JsonKey() final bool isSubmitting;
|
||||
@override final Option<Either<WalletFailure, Unit>> failureOrSuccessOption;
|
||||
|
||||
/// Create a copy of PinSetupFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$PinSetupFormStateCopyWith<_PinSetupFormState> get copyWith => __$PinSetupFormStateCopyWithImpl<_PinSetupFormState>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _PinSetupFormState&&(identical(other.purpose, purpose) || other.purpose == purpose)&&(identical(other.otp, otp) || other.otp == otp)&&(identical(other.isRequestingOtp, isRequestingOtp) || other.isRequestingOtp == isRequestingOtp)&&(identical(other.otpFailureOption, otpFailureOption) || other.otpFailureOption == otpFailureOption)&&(identical(other.resendAvailableAt, resendAvailableAt) || other.resendAvailableAt == resendAvailableAt)&&(identical(other.isSubmitting, isSubmitting) || other.isSubmitting == isSubmitting)&&(identical(other.failureOrSuccessOption, failureOrSuccessOption) || other.failureOrSuccessOption == failureOrSuccessOption));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType,purpose,otp,isRequestingOtp,otpFailureOption,resendAvailableAt,isSubmitting,failureOrSuccessOption);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PinSetupFormState(purpose: $purpose, otp: $otp, isRequestingOtp: $isRequestingOtp, otpFailureOption: $otpFailureOption, resendAvailableAt: $resendAvailableAt, isSubmitting: $isSubmitting, failureOrSuccessOption: $failureOrSuccessOption)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$PinSetupFormStateCopyWith<$Res> implements $PinSetupFormStateCopyWith<$Res> {
|
||||
factory _$PinSetupFormStateCopyWith(_PinSetupFormState value, $Res Function(_PinSetupFormState) _then) = __$PinSetupFormStateCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
PinOtpPurpose purpose, PinOtp? otp, bool isRequestingOtp, Option<WalletFailure> otpFailureOption, DateTime? resendAvailableAt, bool isSubmitting, Option<Either<WalletFailure, Unit>> failureOrSuccessOption
|
||||
});
|
||||
|
||||
|
||||
@override $PinOtpCopyWith<$Res>? get otp;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$PinSetupFormStateCopyWithImpl<$Res>
|
||||
implements _$PinSetupFormStateCopyWith<$Res> {
|
||||
__$PinSetupFormStateCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _PinSetupFormState _self;
|
||||
final $Res Function(_PinSetupFormState) _then;
|
||||
|
||||
/// Create a copy of PinSetupFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? purpose = null,Object? otp = freezed,Object? isRequestingOtp = null,Object? otpFailureOption = null,Object? resendAvailableAt = freezed,Object? isSubmitting = null,Object? failureOrSuccessOption = null,}) {
|
||||
return _then(_PinSetupFormState(
|
||||
purpose: null == purpose ? _self.purpose : purpose // ignore: cast_nullable_to_non_nullable
|
||||
as PinOtpPurpose,otp: freezed == otp ? _self.otp : otp // ignore: cast_nullable_to_non_nullable
|
||||
as PinOtp?,isRequestingOtp: null == isRequestingOtp ? _self.isRequestingOtp : isRequestingOtp // ignore: cast_nullable_to_non_nullable
|
||||
as bool,otpFailureOption: null == otpFailureOption ? _self.otpFailureOption : otpFailureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<WalletFailure>,resendAvailableAt: freezed == resendAvailableAt ? _self.resendAvailableAt : resendAvailableAt // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,isSubmitting: null == isSubmitting ? _self.isSubmitting : isSubmitting // ignore: cast_nullable_to_non_nullable
|
||||
as bool,failureOrSuccessOption: null == failureOrSuccessOption ? _self.failureOrSuccessOption : failureOrSuccessOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<Either<WalletFailure, Unit>>,
|
||||
));
|
||||
}
|
||||
|
||||
/// Create a copy of PinSetupFormState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$PinOtpCopyWith<$Res>? get otp {
|
||||
if (_self.otp == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $PinOtpCopyWith<$Res>(_self.otp!, (value) {
|
||||
return _then(_self.copyWith(otp: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -0,0 +1,14 @@
|
||||
part of 'pin_setup_form_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class PinSetupFormEvent with _$PinSetupFormEvent {
|
||||
const factory PinSetupFormEvent.otpRequested(PinOtpPurpose purpose) =
|
||||
_OtpRequested;
|
||||
|
||||
/// PIN hanya diteruskan ke API, tidak disimpan di state.
|
||||
const factory PinSetupFormEvent.submitted({
|
||||
required String otpCode,
|
||||
required String pin,
|
||||
required String confirmPin,
|
||||
}) = _Submitted;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
part of 'pin_setup_form_bloc.dart';
|
||||
|
||||
@freezed
|
||||
abstract class PinSetupFormState with _$PinSetupFormState {
|
||||
const factory PinSetupFormState({
|
||||
required PinOtpPurpose purpose,
|
||||
PinOtp? otp,
|
||||
@Default(false) bool isRequestingOtp,
|
||||
required Option<WalletFailure> otpFailureOption,
|
||||
|
||||
/// Diisi saat server menjawab `429`; tombol kirim ulang menunggu sampai
|
||||
/// waktu ini.
|
||||
DateTime? resendAvailableAt,
|
||||
@Default(false) bool isSubmitting,
|
||||
required Option<Either<WalletFailure, Unit>> failureOrSuccessOption,
|
||||
}) = _PinSetupFormState;
|
||||
|
||||
factory PinSetupFormState.initial() => PinSetupFormState(
|
||||
purpose: PinOtpPurpose.setup,
|
||||
otpFailureOption: none(),
|
||||
failureOrSuccessOption: none(),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user