TF-474 Use Ever/Worker to listen Obx object

This commit is contained in:
dab246
2022-05-06 18:05:36 +07:00
committed by Dat H. Pham
parent 5cc5ff9761
commit 275fe6faf9
6 changed files with 165 additions and 128 deletions
@@ -121,7 +121,10 @@ class ManageAccountDashBoardView extends GetWidget<ManageAccountDashBoardControl
..addOnTapAvatarActionWithPositionClick((position) =>
controller.openPopupMenuAction(context, position, popupMenuUserSettingActionTile(context,
controller.userProfile.value,
onLogoutAction: () => controller.logoutAction(),
onLogoutAction: () {
popBack();
controller.logoutAction();
},
onSettingAction: () {
popBack();
controller.goToSettings();
@@ -45,6 +45,8 @@ class IdentitiesController extends BaseController {
final idIdentityAll = IdentityId(Id('all'));
late Worker accountIdWorker;
IdentitiesController(
this._getAllIdentitiesInteractor,
this._deleteIdentityInteractor,
@@ -55,10 +57,16 @@ class IdentitiesController extends BaseController {
@override
void onInit() {
_onAccountDashBoardListener();
_initWorker();
super.onInit();
}
@override
void onClose() {
_clearWorker();
super.onClose();
}
@override
void onDone() {
viewState.value.fold(
@@ -91,15 +99,18 @@ class IdentitiesController extends BaseController {
void onError(error) {
}
void _onAccountDashBoardListener() {
_accountDashBoardController.accountId.listen((accountId) {
log('IdentitiesController::_onAccountDashBoardListener(): accountId: $accountId');
if (accountId != null) {
void _initWorker() {
accountIdWorker = ever(_accountDashBoardController.accountId, (accountId) {
if (accountId is AccountId) {
_getAllIdentities(accountId);
}
});
}
void _clearWorker() {
accountIdWorker.call();
}
void _getAllIdentities(AccountId accountId) {
consumeState(_getAllIdentitiesInteractor.execute(accountId));
}