payment method
This commit is contained in:
parent
3135dde317
commit
9e5a6cc7ae
@ -0,0 +1,83 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../domain/payment_method/payment_method.dart';
|
||||
|
||||
part 'payment_method_loader_event.dart';
|
||||
part 'payment_method_loader_state.dart';
|
||||
part 'payment_method_loader_bloc.freezed.dart';
|
||||
|
||||
@injectable
|
||||
class PaymentMethodLoaderBloc
|
||||
extends Bloc<PaymentMethodLoaderEvent, PaymentMethodLoaderState> {
|
||||
final IPaymentMethodRepository _repository;
|
||||
PaymentMethodLoaderBloc(this._repository)
|
||||
: super(PaymentMethodLoaderState.initial()) {
|
||||
on<PaymentMethodLoaderEvent>(_onPaymentMethodLoaderEvent);
|
||||
}
|
||||
|
||||
Future<void> _onPaymentMethodLoaderEvent(
|
||||
PaymentMethodLoaderEvent event,
|
||||
Emitter<PaymentMethodLoaderState> emit,
|
||||
) {
|
||||
return event.map(
|
||||
fetched: (e) async {
|
||||
var newState = state;
|
||||
|
||||
if (e.isRefresh) {
|
||||
newState = newState.copyWith(isFetching: true);
|
||||
emit(newState);
|
||||
}
|
||||
|
||||
newState = await _mapFetchedToState(newState, isRefresh: e.isRefresh);
|
||||
emit(newState);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<PaymentMethodLoaderState> _mapFetchedToState(
|
||||
PaymentMethodLoaderState state, {
|
||||
bool isRefresh = false,
|
||||
}) async {
|
||||
state = state.copyWith(isFetching: false);
|
||||
|
||||
if (state.hasReachedMax && state.paymentMethods.isNotEmpty && !isRefresh) {
|
||||
return state;
|
||||
}
|
||||
|
||||
if (isRefresh) {
|
||||
state = state.copyWith(
|
||||
page: 1,
|
||||
failureOption: none(),
|
||||
hasReachedMax: false,
|
||||
paymentMethods: [],
|
||||
);
|
||||
}
|
||||
|
||||
final failureOrTable = await _repository.getPaymentMethods(
|
||||
page: state.page,
|
||||
);
|
||||
|
||||
state = failureOrTable.fold(
|
||||
(f) {
|
||||
if (state.paymentMethods.isNotEmpty) {
|
||||
return state.copyWith(hasReachedMax: true);
|
||||
}
|
||||
return state.copyWith(failureOption: optionOf(f));
|
||||
},
|
||||
(paymentMethods) {
|
||||
return state.copyWith(
|
||||
paymentMethods: List.from(state.paymentMethods)
|
||||
..addAll(paymentMethods.paymentMethods),
|
||||
failureOption: none(),
|
||||
page: state.page + 1,
|
||||
hasReachedMax: paymentMethods.paymentMethods.length < 10,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,492 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// 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_method_loader_bloc.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
|
||||
);
|
||||
|
||||
/// @nodoc
|
||||
mixin _$PaymentMethodLoaderEvent {
|
||||
bool get isRefresh => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(bool isRefresh) fetched,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function(bool isRefresh)? fetched,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(bool isRefresh)? fetched,
|
||||
required TResult orElse(),
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(_Fetched value) fetched,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(_Fetched value)? fetched,
|
||||
}) => throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(_Fetched value)? fetched,
|
||||
required TResult orElse(),
|
||||
}) => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of PaymentMethodLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$PaymentMethodLoaderEventCopyWith<PaymentMethodLoaderEvent> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $PaymentMethodLoaderEventCopyWith<$Res> {
|
||||
factory $PaymentMethodLoaderEventCopyWith(
|
||||
PaymentMethodLoaderEvent value,
|
||||
$Res Function(PaymentMethodLoaderEvent) then,
|
||||
) = _$PaymentMethodLoaderEventCopyWithImpl<$Res, PaymentMethodLoaderEvent>;
|
||||
@useResult
|
||||
$Res call({bool isRefresh});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$PaymentMethodLoaderEventCopyWithImpl<
|
||||
$Res,
|
||||
$Val extends PaymentMethodLoaderEvent
|
||||
>
|
||||
implements $PaymentMethodLoaderEventCopyWith<$Res> {
|
||||
_$PaymentMethodLoaderEventCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of PaymentMethodLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? isRefresh = null}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
isRefresh: null == isRefresh
|
||||
? _value.isRefresh
|
||||
: isRefresh // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$FetchedImplCopyWith<$Res>
|
||||
implements $PaymentMethodLoaderEventCopyWith<$Res> {
|
||||
factory _$$FetchedImplCopyWith(
|
||||
_$FetchedImpl value,
|
||||
$Res Function(_$FetchedImpl) then,
|
||||
) = __$$FetchedImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({bool isRefresh});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$FetchedImplCopyWithImpl<$Res>
|
||||
extends _$PaymentMethodLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
|
||||
implements _$$FetchedImplCopyWith<$Res> {
|
||||
__$$FetchedImplCopyWithImpl(
|
||||
_$FetchedImpl _value,
|
||||
$Res Function(_$FetchedImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of PaymentMethodLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? isRefresh = null}) {
|
||||
return _then(
|
||||
_$FetchedImpl(
|
||||
isRefresh: null == isRefresh
|
||||
? _value.isRefresh
|
||||
: isRefresh // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$FetchedImpl implements _Fetched {
|
||||
const _$FetchedImpl({this.isRefresh = false});
|
||||
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool isRefresh;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PaymentMethodLoaderEvent.fetched(isRefresh: $isRefresh)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$FetchedImpl &&
|
||||
(identical(other.isRefresh, isRefresh) ||
|
||||
other.isRefresh == isRefresh));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, isRefresh);
|
||||
|
||||
/// Create a copy of PaymentMethodLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
|
||||
__$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(bool isRefresh) fetched,
|
||||
}) {
|
||||
return fetched(isRefresh);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function(bool isRefresh)? fetched,
|
||||
}) {
|
||||
return fetched?.call(isRefresh);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(bool isRefresh)? fetched,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (fetched != null) {
|
||||
return fetched(isRefresh);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(_Fetched value) fetched,
|
||||
}) {
|
||||
return fetched(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(_Fetched value)? fetched,
|
||||
}) {
|
||||
return fetched?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(_Fetched value)? fetched,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (fetched != null) {
|
||||
return fetched(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _Fetched implements PaymentMethodLoaderEvent {
|
||||
const factory _Fetched({final bool isRefresh}) = _$FetchedImpl;
|
||||
|
||||
@override
|
||||
bool get isRefresh;
|
||||
|
||||
/// Create a copy of PaymentMethodLoaderEvent
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$PaymentMethodLoaderState {
|
||||
List<PaymentMethod> get paymentMethods => throw _privateConstructorUsedError;
|
||||
Option<PaymentMethodFailure> get failureOption =>
|
||||
throw _privateConstructorUsedError;
|
||||
bool get hasReachedMax => throw _privateConstructorUsedError;
|
||||
bool get isFetching => throw _privateConstructorUsedError;
|
||||
int get page => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of PaymentMethodLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$PaymentMethodLoaderStateCopyWith<PaymentMethodLoaderState> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $PaymentMethodLoaderStateCopyWith<$Res> {
|
||||
factory $PaymentMethodLoaderStateCopyWith(
|
||||
PaymentMethodLoaderState value,
|
||||
$Res Function(PaymentMethodLoaderState) then,
|
||||
) = _$PaymentMethodLoaderStateCopyWithImpl<$Res, PaymentMethodLoaderState>;
|
||||
@useResult
|
||||
$Res call({
|
||||
List<PaymentMethod> paymentMethods,
|
||||
Option<PaymentMethodFailure> failureOption,
|
||||
bool hasReachedMax,
|
||||
bool isFetching,
|
||||
int page,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$PaymentMethodLoaderStateCopyWithImpl<
|
||||
$Res,
|
||||
$Val extends PaymentMethodLoaderState
|
||||
>
|
||||
implements $PaymentMethodLoaderStateCopyWith<$Res> {
|
||||
_$PaymentMethodLoaderStateCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of PaymentMethodLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? paymentMethods = null,
|
||||
Object? failureOption = null,
|
||||
Object? hasReachedMax = null,
|
||||
Object? isFetching = null,
|
||||
Object? page = null,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
paymentMethods: null == paymentMethods
|
||||
? _value.paymentMethods
|
||||
: paymentMethods // ignore: cast_nullable_to_non_nullable
|
||||
as List<PaymentMethod>,
|
||||
failureOption: null == failureOption
|
||||
? _value.failureOption
|
||||
: failureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<PaymentMethodFailure>,
|
||||
hasReachedMax: null == hasReachedMax
|
||||
? _value.hasReachedMax
|
||||
: hasReachedMax // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
isFetching: null == isFetching
|
||||
? _value.isFetching
|
||||
: isFetching // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
page: null == page
|
||||
? _value.page
|
||||
: page // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$PaymentMethodLoaderStateImplCopyWith<$Res>
|
||||
implements $PaymentMethodLoaderStateCopyWith<$Res> {
|
||||
factory _$$PaymentMethodLoaderStateImplCopyWith(
|
||||
_$PaymentMethodLoaderStateImpl value,
|
||||
$Res Function(_$PaymentMethodLoaderStateImpl) then,
|
||||
) = __$$PaymentMethodLoaderStateImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
List<PaymentMethod> paymentMethods,
|
||||
Option<PaymentMethodFailure> failureOption,
|
||||
bool hasReachedMax,
|
||||
bool isFetching,
|
||||
int page,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$PaymentMethodLoaderStateImplCopyWithImpl<$Res>
|
||||
extends
|
||||
_$PaymentMethodLoaderStateCopyWithImpl<
|
||||
$Res,
|
||||
_$PaymentMethodLoaderStateImpl
|
||||
>
|
||||
implements _$$PaymentMethodLoaderStateImplCopyWith<$Res> {
|
||||
__$$PaymentMethodLoaderStateImplCopyWithImpl(
|
||||
_$PaymentMethodLoaderStateImpl _value,
|
||||
$Res Function(_$PaymentMethodLoaderStateImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of PaymentMethodLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? paymentMethods = null,
|
||||
Object? failureOption = null,
|
||||
Object? hasReachedMax = null,
|
||||
Object? isFetching = null,
|
||||
Object? page = null,
|
||||
}) {
|
||||
return _then(
|
||||
_$PaymentMethodLoaderStateImpl(
|
||||
paymentMethods: null == paymentMethods
|
||||
? _value._paymentMethods
|
||||
: paymentMethods // ignore: cast_nullable_to_non_nullable
|
||||
as List<PaymentMethod>,
|
||||
failureOption: null == failureOption
|
||||
? _value.failureOption
|
||||
: failureOption // ignore: cast_nullable_to_non_nullable
|
||||
as Option<PaymentMethodFailure>,
|
||||
hasReachedMax: null == hasReachedMax
|
||||
? _value.hasReachedMax
|
||||
: hasReachedMax // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
isFetching: null == isFetching
|
||||
? _value.isFetching
|
||||
: isFetching // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
page: null == page
|
||||
? _value.page
|
||||
: page // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$PaymentMethodLoaderStateImpl implements _PaymentMethodLoaderState {
|
||||
_$PaymentMethodLoaderStateImpl({
|
||||
required final List<PaymentMethod> paymentMethods,
|
||||
required this.failureOption,
|
||||
this.hasReachedMax = false,
|
||||
this.isFetching = false,
|
||||
this.page = 1,
|
||||
}) : _paymentMethods = paymentMethods;
|
||||
|
||||
final List<PaymentMethod> _paymentMethods;
|
||||
@override
|
||||
List<PaymentMethod> get paymentMethods {
|
||||
if (_paymentMethods is EqualUnmodifiableListView) return _paymentMethods;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_paymentMethods);
|
||||
}
|
||||
|
||||
@override
|
||||
final Option<PaymentMethodFailure> failureOption;
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool hasReachedMax;
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool isFetching;
|
||||
@override
|
||||
@JsonKey()
|
||||
final int page;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PaymentMethodLoaderState(paymentMethods: $paymentMethods, failureOption: $failureOption, hasReachedMax: $hasReachedMax, isFetching: $isFetching, page: $page)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$PaymentMethodLoaderStateImpl &&
|
||||
const DeepCollectionEquality().equals(
|
||||
other._paymentMethods,
|
||||
_paymentMethods,
|
||||
) &&
|
||||
(identical(other.failureOption, failureOption) ||
|
||||
other.failureOption == failureOption) &&
|
||||
(identical(other.hasReachedMax, hasReachedMax) ||
|
||||
other.hasReachedMax == hasReachedMax) &&
|
||||
(identical(other.isFetching, isFetching) ||
|
||||
other.isFetching == isFetching) &&
|
||||
(identical(other.page, page) || other.page == page));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
const DeepCollectionEquality().hash(_paymentMethods),
|
||||
failureOption,
|
||||
hasReachedMax,
|
||||
isFetching,
|
||||
page,
|
||||
);
|
||||
|
||||
/// Create a copy of PaymentMethodLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$PaymentMethodLoaderStateImplCopyWith<_$PaymentMethodLoaderStateImpl>
|
||||
get copyWith =>
|
||||
__$$PaymentMethodLoaderStateImplCopyWithImpl<
|
||||
_$PaymentMethodLoaderStateImpl
|
||||
>(this, _$identity);
|
||||
}
|
||||
|
||||
abstract class _PaymentMethodLoaderState implements PaymentMethodLoaderState {
|
||||
factory _PaymentMethodLoaderState({
|
||||
required final List<PaymentMethod> paymentMethods,
|
||||
required final Option<PaymentMethodFailure> failureOption,
|
||||
final bool hasReachedMax,
|
||||
final bool isFetching,
|
||||
final int page,
|
||||
}) = _$PaymentMethodLoaderStateImpl;
|
||||
|
||||
@override
|
||||
List<PaymentMethod> get paymentMethods;
|
||||
@override
|
||||
Option<PaymentMethodFailure> get failureOption;
|
||||
@override
|
||||
bool get hasReachedMax;
|
||||
@override
|
||||
bool get isFetching;
|
||||
@override
|
||||
int get page;
|
||||
|
||||
/// Create a copy of PaymentMethodLoaderState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$PaymentMethodLoaderStateImplCopyWith<_$PaymentMethodLoaderStateImpl>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
part of 'payment_method_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
class PaymentMethodLoaderEvent with _$PaymentMethodLoaderEvent {
|
||||
const factory PaymentMethodLoaderEvent.fetched({
|
||||
@Default(false) bool isRefresh,
|
||||
}) = _Fetched;
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
part of 'payment_method_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
class PaymentMethodLoaderState with _$PaymentMethodLoaderState {
|
||||
factory PaymentMethodLoaderState({
|
||||
required List<PaymentMethod> paymentMethods,
|
||||
required Option<PaymentMethodFailure> failureOption,
|
||||
@Default(false) bool hasReachedMax,
|
||||
@Default(false) bool isFetching,
|
||||
@Default(1) int page,
|
||||
}) = _PaymentMethodLoaderState;
|
||||
factory PaymentMethodLoaderState.initial() =>
|
||||
PaymentMethodLoaderState(paymentMethods: [], failureOption: none());
|
||||
}
|
||||
@ -5,4 +5,5 @@ class ApiPath {
|
||||
static const String products = '/api/v1/products';
|
||||
static const String tables = '/api/v1/tables';
|
||||
static const String customers = '/api/v1/customers';
|
||||
static const String paymentMethods = '/api/v1/payment-methods';
|
||||
}
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
part of '../payment_method.dart';
|
||||
|
||||
@freezed
|
||||
class ListPaymentMethod with _$ListPaymentMethod {
|
||||
const factory ListPaymentMethod({
|
||||
required List<PaymentMethod> paymentMethods,
|
||||
required int totalCount,
|
||||
required int page,
|
||||
required int limit,
|
||||
required int totalPages,
|
||||
}) = _ListPaymentMethod;
|
||||
|
||||
factory ListPaymentMethod.empty() => ListPaymentMethod(
|
||||
paymentMethods: [],
|
||||
totalCount: 0,
|
||||
page: 0,
|
||||
limit: 0,
|
||||
totalPages: 0,
|
||||
);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class PaymentMethod with _$PaymentMethod {
|
||||
const factory PaymentMethod({
|
||||
required String id,
|
||||
required String organizationId,
|
||||
required String name,
|
||||
required String type,
|
||||
required bool isActive,
|
||||
required DateTime createdAt,
|
||||
required DateTime updatedAt,
|
||||
}) = _PaymentMethod;
|
||||
|
||||
factory PaymentMethod.empty() => PaymentMethod(
|
||||
id: '',
|
||||
organizationId: '',
|
||||
name: '',
|
||||
type: '',
|
||||
isActive: false,
|
||||
createdAt: DateTime(1970),
|
||||
updatedAt: DateTime(1970),
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
part of '../payment_method.dart';
|
||||
|
||||
@freezed
|
||||
sealed class PaymentMethodFailure with _$PaymentMethodFailure {
|
||||
const factory PaymentMethodFailure.serverError(ApiFailure failure) =
|
||||
_ServerError;
|
||||
const factory PaymentMethodFailure.unexpectedError() = _UnexpectedError;
|
||||
const factory PaymentMethodFailure.empty() = _Empty;
|
||||
const factory PaymentMethodFailure.localStorageError(String erroMessage) =
|
||||
_LocalStorageError;
|
||||
const factory PaymentMethodFailure.dynamicErrorMessage(String erroMessage) =
|
||||
_DynamicErrorMessage;
|
||||
}
|
||||
10
lib/domain/payment_method/payment_method.dart
Normal file
10
lib/domain/payment_method/payment_method.dart
Normal file
@ -0,0 +1,10 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import '../../common/api/api_failure.dart';
|
||||
|
||||
part 'payment_method.freezed.dart';
|
||||
|
||||
part 'entities/payment_method_entity.dart';
|
||||
part 'failures/payment_method_failure.dart';
|
||||
part 'repositories/i_payment_method_repository.dart';
|
||||
1369
lib/domain/payment_method/payment_method.freezed.dart
Normal file
1369
lib/domain/payment_method/payment_method.freezed.dart
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
||||
part of '../payment_method.dart';
|
||||
|
||||
abstract class IPaymentMethodRepository {
|
||||
Future<Either<PaymentMethodFailure, ListPaymentMethod>> getPaymentMethods({
|
||||
int page = 1,
|
||||
int limit = 30,
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:data_channel/data_channel.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../common/api/api_client.dart';
|
||||
import '../../../common/api/api_failure.dart';
|
||||
import '../../../common/function/app_function.dart';
|
||||
import '../../../common/url/api_path.dart';
|
||||
import '../../../domain/payment_method/payment_method.dart';
|
||||
import '../payment_method_dtos.dart';
|
||||
|
||||
@injectable
|
||||
class PaymentMethodRemoteDataProvider {
|
||||
final ApiClient _apiClient;
|
||||
final _logName = 'PaymentMethodRemoteDataProvider';
|
||||
|
||||
PaymentMethodRemoteDataProvider(this._apiClient);
|
||||
|
||||
Future<DC<PaymentMethodFailure, ListPaymentMethodDto>> fetchPaymentMethods({
|
||||
int page = 1,
|
||||
int limit = 30,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _apiClient.get(
|
||||
ApiPath.paymentMethods,
|
||||
params: {'page': page, 'limit': limit},
|
||||
headers: getAuthorizationHeader(),
|
||||
);
|
||||
|
||||
if (response.data['success'] == false) {
|
||||
return DC.error(PaymentMethodFailure.unexpectedError());
|
||||
}
|
||||
|
||||
final paymentMethods = ListPaymentMethodDto.fromJson(
|
||||
response.data['data'] as Map<String, dynamic>,
|
||||
);
|
||||
|
||||
return DC.data(paymentMethods);
|
||||
} on ApiFailure catch (e, s) {
|
||||
log('fetchPaymentMethodsError', name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(PaymentMethodFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
part of '../payment_method_dtos.dart';
|
||||
|
||||
@freezed
|
||||
class ListPaymentMethodDto with _$ListPaymentMethodDto {
|
||||
const ListPaymentMethodDto._();
|
||||
|
||||
const factory ListPaymentMethodDto({
|
||||
@JsonKey(name: "payment_methods") List<PaymentMethodDto>? paymentMethods,
|
||||
@JsonKey(name: "total_count") int? totalCount,
|
||||
@JsonKey(name: "page") int? page,
|
||||
@JsonKey(name: "limit") int? limit,
|
||||
@JsonKey(name: "total_pages") int? totalPages,
|
||||
}) = _ListPaymentMethodDto;
|
||||
|
||||
factory ListPaymentMethodDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$ListPaymentMethodDtoFromJson(json);
|
||||
|
||||
ListPaymentMethod toDomain() => ListPaymentMethod(
|
||||
paymentMethods: paymentMethods?.map((e) => e.toDomain()).toList() ?? [],
|
||||
totalCount: totalCount ?? 0,
|
||||
page: page ?? 0,
|
||||
limit: limit ?? 0,
|
||||
totalPages: totalPages ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class PaymentMethodDto with _$PaymentMethodDto {
|
||||
const PaymentMethodDto._();
|
||||
|
||||
const factory PaymentMethodDto({
|
||||
@JsonKey(name: "id") String? id,
|
||||
@JsonKey(name: "organization_id") String? organizationId,
|
||||
@JsonKey(name: "name") String? name,
|
||||
@JsonKey(name: "type") String? type,
|
||||
@JsonKey(name: "is_active") bool? isActive,
|
||||
@JsonKey(name: "created_at") String? createdAt,
|
||||
@JsonKey(name: "updated_at") String? updatedAt,
|
||||
}) = _PaymentMethodDto;
|
||||
|
||||
factory PaymentMethodDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$PaymentMethodDtoFromJson(json);
|
||||
|
||||
/// Mapping ke domain
|
||||
PaymentMethod toDomain() => PaymentMethod(
|
||||
id: id ?? '',
|
||||
organizationId: organizationId ?? '',
|
||||
name: name ?? '',
|
||||
type: type ?? '',
|
||||
isActive: isActive ?? false,
|
||||
createdAt: createdAt != null ? DateTime.parse(createdAt!) : DateTime(1970),
|
||||
updatedAt: updatedAt != null ? DateTime.parse(updatedAt!) : DateTime(1970),
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import '../../domain/payment_method/payment_method.dart';
|
||||
|
||||
part 'payment_method_dtos.freezed.dart';
|
||||
part 'payment_method_dtos.g.dart';
|
||||
|
||||
part 'dtos/payment_method_dto.dart';
|
||||
@ -0,0 +1,627 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// 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_method_dtos.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
|
||||
);
|
||||
|
||||
ListPaymentMethodDto _$ListPaymentMethodDtoFromJson(Map<String, dynamic> json) {
|
||||
return _ListPaymentMethodDto.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$ListPaymentMethodDto {
|
||||
@JsonKey(name: "payment_methods")
|
||||
List<PaymentMethodDto>? get paymentMethods =>
|
||||
throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "total_count")
|
||||
int? get totalCount => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "page")
|
||||
int? get page => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "limit")
|
||||
int? get limit => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "total_pages")
|
||||
int? get totalPages => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this ListPaymentMethodDto to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of ListPaymentMethodDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$ListPaymentMethodDtoCopyWith<ListPaymentMethodDto> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $ListPaymentMethodDtoCopyWith<$Res> {
|
||||
factory $ListPaymentMethodDtoCopyWith(
|
||||
ListPaymentMethodDto value,
|
||||
$Res Function(ListPaymentMethodDto) then,
|
||||
) = _$ListPaymentMethodDtoCopyWithImpl<$Res, ListPaymentMethodDto>;
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: "payment_methods") List<PaymentMethodDto>? paymentMethods,
|
||||
@JsonKey(name: "total_count") int? totalCount,
|
||||
@JsonKey(name: "page") int? page,
|
||||
@JsonKey(name: "limit") int? limit,
|
||||
@JsonKey(name: "total_pages") int? totalPages,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$ListPaymentMethodDtoCopyWithImpl<
|
||||
$Res,
|
||||
$Val extends ListPaymentMethodDto
|
||||
>
|
||||
implements $ListPaymentMethodDtoCopyWith<$Res> {
|
||||
_$ListPaymentMethodDtoCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of ListPaymentMethodDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? paymentMethods = freezed,
|
||||
Object? totalCount = freezed,
|
||||
Object? page = freezed,
|
||||
Object? limit = freezed,
|
||||
Object? totalPages = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
paymentMethods: freezed == paymentMethods
|
||||
? _value.paymentMethods
|
||||
: paymentMethods // ignore: cast_nullable_to_non_nullable
|
||||
as List<PaymentMethodDto>?,
|
||||
totalCount: freezed == totalCount
|
||||
? _value.totalCount
|
||||
: totalCount // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
page: freezed == page
|
||||
? _value.page
|
||||
: page // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
limit: freezed == limit
|
||||
? _value.limit
|
||||
: limit // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
totalPages: freezed == totalPages
|
||||
? _value.totalPages
|
||||
: totalPages // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ListPaymentMethodDtoImplCopyWith<$Res>
|
||||
implements $ListPaymentMethodDtoCopyWith<$Res> {
|
||||
factory _$$ListPaymentMethodDtoImplCopyWith(
|
||||
_$ListPaymentMethodDtoImpl value,
|
||||
$Res Function(_$ListPaymentMethodDtoImpl) then,
|
||||
) = __$$ListPaymentMethodDtoImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: "payment_methods") List<PaymentMethodDto>? paymentMethods,
|
||||
@JsonKey(name: "total_count") int? totalCount,
|
||||
@JsonKey(name: "page") int? page,
|
||||
@JsonKey(name: "limit") int? limit,
|
||||
@JsonKey(name: "total_pages") int? totalPages,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ListPaymentMethodDtoImplCopyWithImpl<$Res>
|
||||
extends _$ListPaymentMethodDtoCopyWithImpl<$Res, _$ListPaymentMethodDtoImpl>
|
||||
implements _$$ListPaymentMethodDtoImplCopyWith<$Res> {
|
||||
__$$ListPaymentMethodDtoImplCopyWithImpl(
|
||||
_$ListPaymentMethodDtoImpl _value,
|
||||
$Res Function(_$ListPaymentMethodDtoImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of ListPaymentMethodDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? paymentMethods = freezed,
|
||||
Object? totalCount = freezed,
|
||||
Object? page = freezed,
|
||||
Object? limit = freezed,
|
||||
Object? totalPages = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_$ListPaymentMethodDtoImpl(
|
||||
paymentMethods: freezed == paymentMethods
|
||||
? _value._paymentMethods
|
||||
: paymentMethods // ignore: cast_nullable_to_non_nullable
|
||||
as List<PaymentMethodDto>?,
|
||||
totalCount: freezed == totalCount
|
||||
? _value.totalCount
|
||||
: totalCount // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
page: freezed == page
|
||||
? _value.page
|
||||
: page // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
limit: freezed == limit
|
||||
? _value.limit
|
||||
: limit // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
totalPages: freezed == totalPages
|
||||
? _value.totalPages
|
||||
: totalPages // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$ListPaymentMethodDtoImpl extends _ListPaymentMethodDto {
|
||||
const _$ListPaymentMethodDtoImpl({
|
||||
@JsonKey(name: "payment_methods")
|
||||
final List<PaymentMethodDto>? paymentMethods,
|
||||
@JsonKey(name: "total_count") this.totalCount,
|
||||
@JsonKey(name: "page") this.page,
|
||||
@JsonKey(name: "limit") this.limit,
|
||||
@JsonKey(name: "total_pages") this.totalPages,
|
||||
}) : _paymentMethods = paymentMethods,
|
||||
super._();
|
||||
|
||||
factory _$ListPaymentMethodDtoImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$ListPaymentMethodDtoImplFromJson(json);
|
||||
|
||||
final List<PaymentMethodDto>? _paymentMethods;
|
||||
@override
|
||||
@JsonKey(name: "payment_methods")
|
||||
List<PaymentMethodDto>? get paymentMethods {
|
||||
final value = _paymentMethods;
|
||||
if (value == null) return null;
|
||||
if (_paymentMethods is EqualUnmodifiableListView) return _paymentMethods;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(value);
|
||||
}
|
||||
|
||||
@override
|
||||
@JsonKey(name: "total_count")
|
||||
final int? totalCount;
|
||||
@override
|
||||
@JsonKey(name: "page")
|
||||
final int? page;
|
||||
@override
|
||||
@JsonKey(name: "limit")
|
||||
final int? limit;
|
||||
@override
|
||||
@JsonKey(name: "total_pages")
|
||||
final int? totalPages;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ListPaymentMethodDto(paymentMethods: $paymentMethods, totalCount: $totalCount, page: $page, limit: $limit, totalPages: $totalPages)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$ListPaymentMethodDtoImpl &&
|
||||
const DeepCollectionEquality().equals(
|
||||
other._paymentMethods,
|
||||
_paymentMethods,
|
||||
) &&
|
||||
(identical(other.totalCount, totalCount) ||
|
||||
other.totalCount == totalCount) &&
|
||||
(identical(other.page, page) || other.page == page) &&
|
||||
(identical(other.limit, limit) || other.limit == limit) &&
|
||||
(identical(other.totalPages, totalPages) ||
|
||||
other.totalPages == totalPages));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
const DeepCollectionEquality().hash(_paymentMethods),
|
||||
totalCount,
|
||||
page,
|
||||
limit,
|
||||
totalPages,
|
||||
);
|
||||
|
||||
/// Create a copy of ListPaymentMethodDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$ListPaymentMethodDtoImplCopyWith<_$ListPaymentMethodDtoImpl>
|
||||
get copyWith =>
|
||||
__$$ListPaymentMethodDtoImplCopyWithImpl<_$ListPaymentMethodDtoImpl>(
|
||||
this,
|
||||
_$identity,
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$ListPaymentMethodDtoImplToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _ListPaymentMethodDto extends ListPaymentMethodDto {
|
||||
const factory _ListPaymentMethodDto({
|
||||
@JsonKey(name: "payment_methods")
|
||||
final List<PaymentMethodDto>? paymentMethods,
|
||||
@JsonKey(name: "total_count") final int? totalCount,
|
||||
@JsonKey(name: "page") final int? page,
|
||||
@JsonKey(name: "limit") final int? limit,
|
||||
@JsonKey(name: "total_pages") final int? totalPages,
|
||||
}) = _$ListPaymentMethodDtoImpl;
|
||||
const _ListPaymentMethodDto._() : super._();
|
||||
|
||||
factory _ListPaymentMethodDto.fromJson(Map<String, dynamic> json) =
|
||||
_$ListPaymentMethodDtoImpl.fromJson;
|
||||
|
||||
@override
|
||||
@JsonKey(name: "payment_methods")
|
||||
List<PaymentMethodDto>? get paymentMethods;
|
||||
@override
|
||||
@JsonKey(name: "total_count")
|
||||
int? get totalCount;
|
||||
@override
|
||||
@JsonKey(name: "page")
|
||||
int? get page;
|
||||
@override
|
||||
@JsonKey(name: "limit")
|
||||
int? get limit;
|
||||
@override
|
||||
@JsonKey(name: "total_pages")
|
||||
int? get totalPages;
|
||||
|
||||
/// Create a copy of ListPaymentMethodDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$ListPaymentMethodDtoImplCopyWith<_$ListPaymentMethodDtoImpl>
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
PaymentMethodDto _$PaymentMethodDtoFromJson(Map<String, dynamic> json) {
|
||||
return _PaymentMethodDto.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$PaymentMethodDto {
|
||||
@JsonKey(name: "id")
|
||||
String? get id => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "organization_id")
|
||||
String? get organizationId => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "name")
|
||||
String? get name => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "type")
|
||||
String? get type => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "is_active")
|
||||
bool? get isActive => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "created_at")
|
||||
String? get createdAt => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "updated_at")
|
||||
String? get updatedAt => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this PaymentMethodDto to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of PaymentMethodDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$PaymentMethodDtoCopyWith<PaymentMethodDto> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $PaymentMethodDtoCopyWith<$Res> {
|
||||
factory $PaymentMethodDtoCopyWith(
|
||||
PaymentMethodDto value,
|
||||
$Res Function(PaymentMethodDto) then,
|
||||
) = _$PaymentMethodDtoCopyWithImpl<$Res, PaymentMethodDto>;
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: "id") String? id,
|
||||
@JsonKey(name: "organization_id") String? organizationId,
|
||||
@JsonKey(name: "name") String? name,
|
||||
@JsonKey(name: "type") String? type,
|
||||
@JsonKey(name: "is_active") bool? isActive,
|
||||
@JsonKey(name: "created_at") String? createdAt,
|
||||
@JsonKey(name: "updated_at") String? updatedAt,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$PaymentMethodDtoCopyWithImpl<$Res, $Val extends PaymentMethodDto>
|
||||
implements $PaymentMethodDtoCopyWith<$Res> {
|
||||
_$PaymentMethodDtoCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of PaymentMethodDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = freezed,
|
||||
Object? organizationId = freezed,
|
||||
Object? name = freezed,
|
||||
Object? type = freezed,
|
||||
Object? isActive = freezed,
|
||||
Object? createdAt = freezed,
|
||||
Object? updatedAt = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
id: freezed == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
organizationId: freezed == organizationId
|
||||
? _value.organizationId
|
||||
: organizationId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
name: freezed == name
|
||||
? _value.name
|
||||
: name // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
type: freezed == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
isActive: freezed == isActive
|
||||
? _value.isActive
|
||||
: isActive // ignore: cast_nullable_to_non_nullable
|
||||
as bool?,
|
||||
createdAt: freezed == createdAt
|
||||
? _value.createdAt
|
||||
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
updatedAt: freezed == updatedAt
|
||||
? _value.updatedAt
|
||||
: updatedAt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$PaymentMethodDtoImplCopyWith<$Res>
|
||||
implements $PaymentMethodDtoCopyWith<$Res> {
|
||||
factory _$$PaymentMethodDtoImplCopyWith(
|
||||
_$PaymentMethodDtoImpl value,
|
||||
$Res Function(_$PaymentMethodDtoImpl) then,
|
||||
) = __$$PaymentMethodDtoImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: "id") String? id,
|
||||
@JsonKey(name: "organization_id") String? organizationId,
|
||||
@JsonKey(name: "name") String? name,
|
||||
@JsonKey(name: "type") String? type,
|
||||
@JsonKey(name: "is_active") bool? isActive,
|
||||
@JsonKey(name: "created_at") String? createdAt,
|
||||
@JsonKey(name: "updated_at") String? updatedAt,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$PaymentMethodDtoImplCopyWithImpl<$Res>
|
||||
extends _$PaymentMethodDtoCopyWithImpl<$Res, _$PaymentMethodDtoImpl>
|
||||
implements _$$PaymentMethodDtoImplCopyWith<$Res> {
|
||||
__$$PaymentMethodDtoImplCopyWithImpl(
|
||||
_$PaymentMethodDtoImpl _value,
|
||||
$Res Function(_$PaymentMethodDtoImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of PaymentMethodDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = freezed,
|
||||
Object? organizationId = freezed,
|
||||
Object? name = freezed,
|
||||
Object? type = freezed,
|
||||
Object? isActive = freezed,
|
||||
Object? createdAt = freezed,
|
||||
Object? updatedAt = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_$PaymentMethodDtoImpl(
|
||||
id: freezed == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
organizationId: freezed == organizationId
|
||||
? _value.organizationId
|
||||
: organizationId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
name: freezed == name
|
||||
? _value.name
|
||||
: name // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
type: freezed == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
isActive: freezed == isActive
|
||||
? _value.isActive
|
||||
: isActive // ignore: cast_nullable_to_non_nullable
|
||||
as bool?,
|
||||
createdAt: freezed == createdAt
|
||||
? _value.createdAt
|
||||
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
updatedAt: freezed == updatedAt
|
||||
? _value.updatedAt
|
||||
: updatedAt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$PaymentMethodDtoImpl extends _PaymentMethodDto {
|
||||
const _$PaymentMethodDtoImpl({
|
||||
@JsonKey(name: "id") this.id,
|
||||
@JsonKey(name: "organization_id") this.organizationId,
|
||||
@JsonKey(name: "name") this.name,
|
||||
@JsonKey(name: "type") this.type,
|
||||
@JsonKey(name: "is_active") this.isActive,
|
||||
@JsonKey(name: "created_at") this.createdAt,
|
||||
@JsonKey(name: "updated_at") this.updatedAt,
|
||||
}) : super._();
|
||||
|
||||
factory _$PaymentMethodDtoImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$PaymentMethodDtoImplFromJson(json);
|
||||
|
||||
@override
|
||||
@JsonKey(name: "id")
|
||||
final String? id;
|
||||
@override
|
||||
@JsonKey(name: "organization_id")
|
||||
final String? organizationId;
|
||||
@override
|
||||
@JsonKey(name: "name")
|
||||
final String? name;
|
||||
@override
|
||||
@JsonKey(name: "type")
|
||||
final String? type;
|
||||
@override
|
||||
@JsonKey(name: "is_active")
|
||||
final bool? isActive;
|
||||
@override
|
||||
@JsonKey(name: "created_at")
|
||||
final String? createdAt;
|
||||
@override
|
||||
@JsonKey(name: "updated_at")
|
||||
final String? updatedAt;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PaymentMethodDto(id: $id, organizationId: $organizationId, name: $name, type: $type, isActive: $isActive, createdAt: $createdAt, updatedAt: $updatedAt)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$PaymentMethodDtoImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.organizationId, organizationId) ||
|
||||
other.organizationId == organizationId) &&
|
||||
(identical(other.name, name) || other.name == name) &&
|
||||
(identical(other.type, type) || other.type == type) &&
|
||||
(identical(other.isActive, isActive) ||
|
||||
other.isActive == isActive) &&
|
||||
(identical(other.createdAt, createdAt) ||
|
||||
other.createdAt == createdAt) &&
|
||||
(identical(other.updatedAt, updatedAt) ||
|
||||
other.updatedAt == updatedAt));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
id,
|
||||
organizationId,
|
||||
name,
|
||||
type,
|
||||
isActive,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
);
|
||||
|
||||
/// Create a copy of PaymentMethodDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$PaymentMethodDtoImplCopyWith<_$PaymentMethodDtoImpl> get copyWith =>
|
||||
__$$PaymentMethodDtoImplCopyWithImpl<_$PaymentMethodDtoImpl>(
|
||||
this,
|
||||
_$identity,
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$PaymentMethodDtoImplToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _PaymentMethodDto extends PaymentMethodDto {
|
||||
const factory _PaymentMethodDto({
|
||||
@JsonKey(name: "id") final String? id,
|
||||
@JsonKey(name: "organization_id") final String? organizationId,
|
||||
@JsonKey(name: "name") final String? name,
|
||||
@JsonKey(name: "type") final String? type,
|
||||
@JsonKey(name: "is_active") final bool? isActive,
|
||||
@JsonKey(name: "created_at") final String? createdAt,
|
||||
@JsonKey(name: "updated_at") final String? updatedAt,
|
||||
}) = _$PaymentMethodDtoImpl;
|
||||
const _PaymentMethodDto._() : super._();
|
||||
|
||||
factory _PaymentMethodDto.fromJson(Map<String, dynamic> json) =
|
||||
_$PaymentMethodDtoImpl.fromJson;
|
||||
|
||||
@override
|
||||
@JsonKey(name: "id")
|
||||
String? get id;
|
||||
@override
|
||||
@JsonKey(name: "organization_id")
|
||||
String? get organizationId;
|
||||
@override
|
||||
@JsonKey(name: "name")
|
||||
String? get name;
|
||||
@override
|
||||
@JsonKey(name: "type")
|
||||
String? get type;
|
||||
@override
|
||||
@JsonKey(name: "is_active")
|
||||
bool? get isActive;
|
||||
@override
|
||||
@JsonKey(name: "created_at")
|
||||
String? get createdAt;
|
||||
@override
|
||||
@JsonKey(name: "updated_at")
|
||||
String? get updatedAt;
|
||||
|
||||
/// Create a copy of PaymentMethodDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$PaymentMethodDtoImplCopyWith<_$PaymentMethodDtoImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
53
lib/infrastructure/payment_method/payment_method_dtos.g.dart
Normal file
53
lib/infrastructure/payment_method/payment_method_dtos.g.dart
Normal file
@ -0,0 +1,53 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'payment_method_dtos.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$ListPaymentMethodDtoImpl _$$ListPaymentMethodDtoImplFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$ListPaymentMethodDtoImpl(
|
||||
paymentMethods: (json['payment_methods'] as List<dynamic>?)
|
||||
?.map((e) => PaymentMethodDto.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
totalCount: (json['total_count'] as num?)?.toInt(),
|
||||
page: (json['page'] as num?)?.toInt(),
|
||||
limit: (json['limit'] as num?)?.toInt(),
|
||||
totalPages: (json['total_pages'] as num?)?.toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ListPaymentMethodDtoImplToJson(
|
||||
_$ListPaymentMethodDtoImpl instance,
|
||||
) => <String, dynamic>{
|
||||
'payment_methods': instance.paymentMethods,
|
||||
'total_count': instance.totalCount,
|
||||
'page': instance.page,
|
||||
'limit': instance.limit,
|
||||
'total_pages': instance.totalPages,
|
||||
};
|
||||
|
||||
_$PaymentMethodDtoImpl _$$PaymentMethodDtoImplFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$PaymentMethodDtoImpl(
|
||||
id: json['id'] as String?,
|
||||
organizationId: json['organization_id'] as String?,
|
||||
name: json['name'] as String?,
|
||||
type: json['type'] as String?,
|
||||
isActive: json['is_active'] as bool?,
|
||||
createdAt: json['created_at'] as String?,
|
||||
updatedAt: json['updated_at'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$PaymentMethodDtoImplToJson(
|
||||
_$PaymentMethodDtoImpl instance,
|
||||
) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'organization_id': instance.organizationId,
|
||||
'name': instance.name,
|
||||
'type': instance.type,
|
||||
'is_active': instance.isActive,
|
||||
'created_at': instance.createdAt,
|
||||
'updated_at': instance.updatedAt,
|
||||
};
|
||||
@ -0,0 +1,38 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../domain/payment_method/payment_method.dart';
|
||||
import '../datasources/remote_data_provider.dart';
|
||||
|
||||
@Injectable(as: IPaymentMethodRepository)
|
||||
class PaymentMethodRepository implements IPaymentMethodRepository {
|
||||
final PaymentMethodRemoteDataProvider _remoteDataProvider;
|
||||
final _logName = 'PaymentMethodRepository';
|
||||
|
||||
PaymentMethodRepository(this._remoteDataProvider);
|
||||
|
||||
@override
|
||||
Future<Either<PaymentMethodFailure, ListPaymentMethod>> getPaymentMethods({
|
||||
int page = 1,
|
||||
int limit = 30,
|
||||
}) async {
|
||||
try {
|
||||
final result = await _remoteDataProvider.fetchPaymentMethods(
|
||||
page: page,
|
||||
limit: limit,
|
||||
);
|
||||
|
||||
if (result.hasError) {
|
||||
return left(result.error!);
|
||||
}
|
||||
|
||||
final paymentMethods = result.data!.toDomain();
|
||||
return right(paymentMethods);
|
||||
} catch (e) {
|
||||
log('getPaymentMethodError', name: _logName, error: e);
|
||||
return left(const PaymentMethodFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -20,6 +20,8 @@ import 'package:apskel_pos_flutter_v2/application/customer/customer_loader/custo
|
||||
as _i683;
|
||||
import 'package:apskel_pos_flutter_v2/application/outlet/outlet_loader/outlet_loader_bloc.dart'
|
||||
as _i76;
|
||||
import 'package:apskel_pos_flutter_v2/application/payment_method/payment_method_loader/payment_method_loader_bloc.dart'
|
||||
as _i952;
|
||||
import 'package:apskel_pos_flutter_v2/application/product/product_loader/product_loader_bloc.dart'
|
||||
as _i13;
|
||||
import 'package:apskel_pos_flutter_v2/application/sync/sync_bloc.dart' as _i741;
|
||||
@ -42,6 +44,8 @@ import 'package:apskel_pos_flutter_v2/domain/auth/auth.dart' as _i776;
|
||||
import 'package:apskel_pos_flutter_v2/domain/category/category.dart' as _i502;
|
||||
import 'package:apskel_pos_flutter_v2/domain/customer/customer.dart' as _i143;
|
||||
import 'package:apskel_pos_flutter_v2/domain/outlet/outlet.dart' as _i552;
|
||||
import 'package:apskel_pos_flutter_v2/domain/payment_method/payment_method.dart'
|
||||
as _i297;
|
||||
import 'package:apskel_pos_flutter_v2/domain/product/product.dart' as _i44;
|
||||
import 'package:apskel_pos_flutter_v2/domain/table/table.dart' as _i983;
|
||||
import 'package:apskel_pos_flutter_v2/env.dart' as _i923;
|
||||
@ -67,6 +71,10 @@ import 'package:apskel_pos_flutter_v2/infrastructure/outlet/datasources/remote_d
|
||||
as _i132;
|
||||
import 'package:apskel_pos_flutter_v2/infrastructure/outlet/repositories/outlet_repository.dart'
|
||||
as _i845;
|
||||
import 'package:apskel_pos_flutter_v2/infrastructure/payment_method/datasources/remote_data_provider.dart'
|
||||
as _i833;
|
||||
import 'package:apskel_pos_flutter_v2/infrastructure/payment_method/repositories/payment_method_repository.dart'
|
||||
as _i167;
|
||||
import 'package:apskel_pos_flutter_v2/infrastructure/product/datasources/local_data_provider.dart'
|
||||
as _i464;
|
||||
import 'package:apskel_pos_flutter_v2/infrastructure/product/datasources/remote_data_provider.dart'
|
||||
@ -147,6 +155,9 @@ extension GetItInjectableX on _i174.GetIt {
|
||||
gh.factory<_i841.CustomerRemoteDataProvider>(
|
||||
() => _i841.CustomerRemoteDataProvider(gh<_i457.ApiClient>()),
|
||||
);
|
||||
gh.factory<_i833.PaymentMethodRemoteDataProvider>(
|
||||
() => _i833.PaymentMethodRemoteDataProvider(gh<_i457.ApiClient>()),
|
||||
);
|
||||
gh.factory<_i776.IAuthRepository>(
|
||||
() => _i941.AuthRepository(
|
||||
gh<_i370.AuthRemoteDataProvider>(),
|
||||
@ -183,6 +194,11 @@ extension GetItInjectableX on _i174.GetIt {
|
||||
gh<_i693.OutletLocalDatasource>(),
|
||||
),
|
||||
);
|
||||
gh.factory<_i297.IPaymentMethodRepository>(
|
||||
() => _i167.PaymentMethodRepository(
|
||||
gh<_i833.PaymentMethodRemoteDataProvider>(),
|
||||
),
|
||||
);
|
||||
gh.factory<_i46.LoginFormBloc>(
|
||||
() => _i46.LoginFormBloc(gh<_i776.IAuthRepository>()),
|
||||
);
|
||||
@ -195,6 +211,9 @@ extension GetItInjectableX on _i174.GetIt {
|
||||
gh.factory<_i683.CustomerLoaderBloc>(
|
||||
() => _i683.CustomerLoaderBloc(gh<_i143.ICustomerRepository>()),
|
||||
);
|
||||
gh.factory<_i952.PaymentMethodLoaderBloc>(
|
||||
() => _i952.PaymentMethodLoaderBloc(gh<_i297.IPaymentMethodRepository>()),
|
||||
);
|
||||
gh.factory<_i343.AuthBloc>(
|
||||
() => _i343.AuthBloc(
|
||||
gh<_i776.IAuthRepository>(),
|
||||
|
||||
@ -5,6 +5,7 @@ import '../application/auth/auth_bloc.dart';
|
||||
import '../application/category/category_loader/category_loader_bloc.dart';
|
||||
import '../application/checkout/checkout_form/checkout_form_bloc.dart';
|
||||
import '../application/outlet/outlet_loader/outlet_loader_bloc.dart';
|
||||
import '../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart';
|
||||
import '../application/product/product_loader/product_loader_bloc.dart';
|
||||
import '../application/table/table_form/table_form_bloc.dart';
|
||||
import '../application/table/table_loader/table_loader_bloc.dart';
|
||||
@ -35,6 +36,7 @@ class _AppWidgetState extends State<AppWidget> {
|
||||
BlocProvider(create: (context) => getIt<CheckoutFormBloc>()),
|
||||
BlocProvider(create: (context) => getIt<TableLoaderBloc>()),
|
||||
BlocProvider(create: (context) => getIt<TableFormBloc>()),
|
||||
BlocProvider(create: (context) => getIt<PaymentMethodLoaderBloc>()),
|
||||
],
|
||||
child: MaterialApp.router(
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
||||
37
lib/presentation/components/card/payment_card.dart
Normal file
37
lib/presentation/components/card/payment_card.dart
Normal file
@ -0,0 +1,37 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../domain/payment_method/payment_method.dart';
|
||||
|
||||
class PaymentCard extends StatelessWidget {
|
||||
final PaymentMethod payment;
|
||||
final bool isSelected;
|
||||
final Function(bool)? onSelected;
|
||||
const PaymentCard({
|
||||
super.key,
|
||||
required this.payment,
|
||||
required this.isSelected,
|
||||
this.onSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChoiceChip(
|
||||
label: Text(payment.name),
|
||||
selected: isSelected,
|
||||
onSelected: onSelected,
|
||||
selectedColor: AppColor.primary,
|
||||
backgroundColor: AppColor.white,
|
||||
labelStyle: TextStyle(
|
||||
color: isSelected ? AppColor.white : AppColor.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
checkmarkColor: AppColor.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
side: BorderSide(color: AppColor.primary),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart';
|
||||
import '../../../domain/payment_method/payment_method.dart';
|
||||
import '../card/error_card.dart';
|
||||
|
||||
class PaymentMethodErrorStateWidget extends StatelessWidget {
|
||||
final PaymentMethodFailure failure;
|
||||
const PaymentMethodErrorStateWidget({super.key, required this.failure});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return failure.maybeMap(
|
||||
orElse: () => ErrorCard(
|
||||
title: 'Metode Pembayaran',
|
||||
message: 'Terjadi Kesalahan saat memuat metode pembayaran',
|
||||
onTap: () {
|
||||
context.read<PaymentMethodLoaderBloc>().add(
|
||||
PaymentMethodLoaderEvent.fetched(isRefresh: true),
|
||||
);
|
||||
},
|
||||
),
|
||||
dynamicErrorMessage: (value) => ErrorCard(
|
||||
title: 'Metode Pembayaran',
|
||||
message: value.erroMessage,
|
||||
onTap: () {
|
||||
context.read<PaymentMethodLoaderBloc>().add(
|
||||
PaymentMethodLoaderEvent.fetched(isRefresh: true),
|
||||
);
|
||||
},
|
||||
),
|
||||
empty: (value) => ErrorCard(
|
||||
title: 'Metode Pembayaran',
|
||||
message:
|
||||
'Metode pembayaran masih kosong, silahkan tambahkan metode pembayaran',
|
||||
onTap: () {
|
||||
context.read<PaymentMethodLoaderBloc>().add(
|
||||
PaymentMethodLoaderEvent.fetched(isRefresh: true),
|
||||
);
|
||||
},
|
||||
),
|
||||
serverError: (value) => ErrorCard(
|
||||
title: 'Metode Pembayaran',
|
||||
message: 'Terjadi Kesalahan saat memuat metode pembayaran',
|
||||
onTap: () {
|
||||
context.read<PaymentMethodLoaderBloc>().add(
|
||||
PaymentMethodLoaderEvent.fetched(isRefresh: true),
|
||||
);
|
||||
},
|
||||
),
|
||||
localStorageError: (value) => ErrorCard(
|
||||
title: 'Metode Pembayaran',
|
||||
message: value.erroMessage,
|
||||
onTap: () {
|
||||
context.read<PaymentMethodLoaderBloc>().add(
|
||||
PaymentMethodLoaderEvent.fetched(isRefresh: true),
|
||||
);
|
||||
},
|
||||
),
|
||||
unexpectedError: (value) => ErrorCard(
|
||||
title: 'Metode Pembayaran',
|
||||
message: 'Terjadi Kesalahan saat memuat metode pembayaran',
|
||||
onTap: () {
|
||||
context.read<PaymentMethodLoaderBloc>().add(
|
||||
PaymentMethodLoaderEvent.fetched(isRefresh: true),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -3,13 +3,15 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../application/checkout/checkout_form/checkout_form_bloc.dart';
|
||||
import '../../../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart';
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../injection.dart';
|
||||
import '../../components/spaces/space.dart';
|
||||
import 'widgets/checkout_left_panel.dart';
|
||||
import 'widgets/checkout_right_panel.dart';
|
||||
|
||||
@RoutePage()
|
||||
class CheckoutPage extends StatelessWidget {
|
||||
class CheckoutPage extends StatelessWidget implements AutoRouteWrapper {
|
||||
const CheckoutPage({super.key});
|
||||
|
||||
@override
|
||||
@ -49,4 +51,12 @@ class CheckoutPage extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget wrappedRoute(BuildContext context) => BlocProvider(
|
||||
create: (context) =>
|
||||
getIt<PaymentMethodLoaderBloc>()
|
||||
..add(PaymentMethodLoaderEvent.fetched(isRefresh: true)),
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart';
|
||||
import '../../../../common/theme/theme.dart';
|
||||
import '../../../components/field/field.dart';
|
||||
import '../../../components/card/payment_card.dart';
|
||||
import '../../../components/error/payment_method_error_state_widget.dart';
|
||||
import '../../../components/loader/loader_with_text.dart';
|
||||
import '../../../components/page/page_title.dart';
|
||||
import '../../../components/spaces/space.dart';
|
||||
|
||||
class CheckoutRightPanel extends StatelessWidget {
|
||||
const CheckoutRightPanel({super.key});
|
||||
@ -38,6 +43,51 @@ class CheckoutRightPanel extends StatelessWidget {
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.white,
|
||||
border: Border(
|
||||
bottom: BorderSide(color: AppColor.border, width: 1.0),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Metode Pembayaran',
|
||||
style: AppStyle.lg.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SpaceHeight(12.0),
|
||||
BlocBuilder<
|
||||
PaymentMethodLoaderBloc,
|
||||
PaymentMethodLoaderState
|
||||
>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetching) {
|
||||
return Center(child: LoaderWithText());
|
||||
}
|
||||
return state.failureOption.fold(
|
||||
() => Wrap(
|
||||
spacing: 12.0,
|
||||
runSpacing: 8.0,
|
||||
children: state.paymentMethods.map((item) {
|
||||
return PaymentCard(
|
||||
payment: item,
|
||||
isSelected: true,
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
(f) => PaymentMethodErrorStateWidget(failure: f),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user