Files
enaklo-flutter/lib/application/voucher/voucher_loader/voucher_loader_bloc.dart
T
efrilm 38850b281f
Build & Deploy iOS to TestFlight / build-and-deploy (push) Canceled after 0s
feat: integrate enakgame and voucher
2026-10-10 02:33:16 +07:00

41 lines
1.2 KiB
Dart

import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/wallet/wallet.dart';
part 'voucher_loader_event.dart';
part 'voucher_loader_state.dart';
part 'voucher_loader_bloc.freezed.dart';
/// Katalog voucher yang bisa ditukar (ยง9.1).
@injectable
class VoucherLoaderBloc extends Bloc<VoucherLoaderEvent, VoucherLoaderState> {
final IVoucherRepository _repository;
VoucherLoaderBloc(this._repository) : super(VoucherLoaderState.initial()) {
on<VoucherLoaderEvent>(_onVoucherLoaderEvent);
}
Future<void> _onVoucherLoaderEvent(
VoucherLoaderEvent event,
Emitter<VoucherLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(state.copyWith(isFetching: true, failureOption: none()));
final result = await _repository.getVouchers();
final data = result.fold(
(f) => state.copyWith(failureOption: optionOf(f)),
(vouchers) => state.copyWith(vouchers: vouchers, hasLoaded: true),
);
emit(data.copyWith(isFetching: false));
},
);
}
}