'Flutter, listen to states without BlocListener from flutter bloc package
I make purchases with in_app_purchase library, and i also using bloc, because i am not that good at bloc yet i copied code from in_app_purchase examples.
this is my listenToPurchaseUpdated function
void _listenToPurchaseUpdated(List<PurchaseDetails> purchaseDetailsList) {
purchaseDetailsList.forEach((PurchaseDetails purchaseDetails) async {
if (purchaseDetails.status == PurchaseStatus.purchased) {
await _checkListRepotisory.userDidPurchase(purchaseDetails.productID);
CheckListTemplate template = await addCheckListWhenUserBuyIt(purchaseDetails.productID, _checkListRepotisory);
addCheckListBloc.add(AddNewCheckList(template, ""));
}
if (purchaseDetails.status == PurchaseStatus.restored) {
_restoredProducts.add(purchaseDetails.productID);
}
if (purchaseDetails.pendingCompletePurchase) {
await _inAppPurchase.completePurchase(purchaseDetails);
}
});
}
i create bloc without of context in this way
final AddCheckListBloc addCheckListBloc = AddCheckListBloc(checkListRepository: CheckListRepository(localStorage: LocalStorage.instanse, serverStorage: ServerStorage.instanse));
In the end of AddCheckListevent i emit state NewCheckListAddedState and i need listen to it, to navigate to other screen. How i can do it ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
