From 058522caf1f1250c61ff9ad0408cae0e8e1e2150 Mon Sep 17 00:00:00 2001 From: Omar Hatem Date: Sun, 26 May 2024 18:09:39 +0300 Subject: [PATCH] Fix Contact page reaction excuted more than once (#1467) --- lib/src/screens/contact/contact_page.dart | 29 ++++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/src/screens/contact/contact_page.dart b/lib/src/screens/contact/contact_page.dart index 099be41d5..7dea970ec 100644 --- a/lib/src/screens/contact/contact_page.dart +++ b/lib/src/screens/contact/contact_page.dart @@ -46,6 +46,7 @@ class ContactPage extends BasePage { final TextEditingController _nameController; final TextEditingController _currencyTypeController; final TextEditingController _addressController; + bool _isEffectsApplied = false; @override Widget body(BuildContext context) { @@ -53,15 +54,7 @@ class ContactPage extends BasePage { color: Theme.of(context).extension()!.detailsTitlesColor, height: 8); - reaction((_) => contactViewModel.state, (ExecutionState state) { - if (state is FailureState) { - _onContactSavingFailure(context, state.error); - } - - if (state is ExecutedSuccessfullyState) { - _onContactSavedSuccessfully(context); - } - }); + _setEffects(context); return Observer( builder: (_) => ScrollableWithBottomSection( @@ -177,4 +170,22 @@ class ContactPage extends BasePage { void _onContactSavedSuccessfully(BuildContext context) => Navigator.of(context).pop(); + + void _setEffects(BuildContext context) { + if (_isEffectsApplied) { + return; + } + + _isEffectsApplied = true; + + reaction((_) => contactViewModel.state, (ExecutionState state) { + if (state is FailureState) { + _onContactSavingFailure(context, state.error); + } + + if (state is ExecutedSuccessfullyState) { + _onContactSavedSuccessfully(context); + } + }); + } }