WT 1.1.26+3 bloc migration
This commit is contained in:
@@ -27,12 +27,51 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
|
||||
int productSet = -1;
|
||||
final DescriptionRepository descriptionRepository = DescriptionRepository();
|
||||
SalesBloc() : super(SalesInitial());
|
||||
SalesBloc() : super(SalesInitial()) {
|
||||
on<SalesLoad>(_onLoad);
|
||||
on<SalesPurchase>(_onPurchase);
|
||||
}
|
||||
|
||||
String? salesText;
|
||||
String? premiumFunctions = "";
|
||||
String? trial = "";
|
||||
|
||||
void _onLoad(SalesLoad event, Emitter<SalesState> emit) async {
|
||||
emit(SalesLoading());
|
||||
await init();
|
||||
emit(SalesReady());
|
||||
}
|
||||
|
||||
void _onPurchase(SalesPurchase event, Emitter<SalesState> emit) async {
|
||||
if (Cache().hasPurchased) {
|
||||
throw Exception("You have already a successfull subscription");
|
||||
}
|
||||
emit(SalesLoading());
|
||||
final int productId = event.productId;
|
||||
log("Requesting purchase for: " + productId.toString());
|
||||
Track().track(TrackingEvent.purchase_request);
|
||||
final Product? selectedProduct = this.getSelectedProduct(productId);
|
||||
log("SelectedProduct for purchase $selectedProduct");
|
||||
if (selectedProduct != null) {
|
||||
await RevenueCatPurchases().makePurchase(selectedProduct);
|
||||
if (Cache().hasPurchased) {
|
||||
Purchase purchase = Purchase(customerId: Cache().userLoggedIn!.customerId!, productId: productId);
|
||||
purchase.dateAdd = DateTime.now();
|
||||
purchase.purchaseSum = 0;
|
||||
purchase.currency = "EUR";
|
||||
await PurchaseApi().savePurchase(purchase);
|
||||
Track().track(TrackingEvent.purchase_successful, eventValue: selectedProduct.localizedPrice.toString());
|
||||
CustomerRepository customerRepository = CustomerRepository();
|
||||
customerRepository.customer = Cache().userLoggedIn;
|
||||
MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository);
|
||||
await mauticRepository.sendMauticPurchase();
|
||||
}
|
||||
emit(SalesSuccessful());
|
||||
} else {
|
||||
emit(SalesError(message: "No selected product"));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
if (Cache().userLoggedIn == null) {
|
||||
throw Exception("Please log in");
|
||||
@@ -60,51 +99,6 @@ class SalesBloc extends Bloc<SalesEvent, SalesState> with Logging {
|
||||
Track().track(TrackingEvent.sales_page);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<SalesState> mapEventToState(
|
||||
SalesEvent event,
|
||||
) async* {
|
||||
try {
|
||||
if (event is SalesLoad) {
|
||||
log(" -- start SalesLoad");
|
||||
yield SalesLoading();
|
||||
await init();
|
||||
yield SalesReady();
|
||||
log(" -- finish SalesLoad");
|
||||
} else if (event is SalesPurchase) {
|
||||
if (Cache().hasPurchased) {
|
||||
throw Exception("You have already a successfull subscription");
|
||||
}
|
||||
yield SalesLoading();
|
||||
final int productId = event.productId;
|
||||
log("Requesting purchase for: " + productId.toString());
|
||||
Track().track(TrackingEvent.purchase_request);
|
||||
final Product? selectedProduct = this.getSelectedProduct(productId);
|
||||
log("SelectedProduct for purchase $selectedProduct");
|
||||
if (selectedProduct != null) {
|
||||
await RevenueCatPurchases().makePurchase(selectedProduct);
|
||||
if (Cache().hasPurchased) {
|
||||
Purchase purchase = Purchase(customerId: Cache().userLoggedIn!.customerId!, productId: productId);
|
||||
purchase.dateAdd = DateTime.now();
|
||||
purchase.purchaseSum = 0;
|
||||
purchase.currency = "EUR";
|
||||
await PurchaseApi().savePurchase(purchase);
|
||||
Track().track(TrackingEvent.purchase_successful, eventValue: selectedProduct.localizedPrice.toString());
|
||||
CustomerRepository customerRepository = CustomerRepository();
|
||||
customerRepository.customer = Cache().userLoggedIn;
|
||||
MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository);
|
||||
await mauticRepository.sendMauticPurchase();
|
||||
}
|
||||
yield SalesSuccessful();
|
||||
} else {
|
||||
yield SalesError(message: "No selected product");
|
||||
}
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
yield SalesError(message: ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void getProductsTexts() {
|
||||
Product product;
|
||||
if (product2Display.isNotEmpty) {
|
||||
|
||||
Reference in New Issue
Block a user