Fix Contact page reaction excuted more than once (#1467)
Omar Hatem committed
May 26, 2024 at 18:09 UTC
058522caf1f1250c61ff9ad0408cae0e8e1e2150
1 file changed
+20
-9
lib/src/screens/contact/contact_page.dart
+20
-9
@@ -46,6 +46,7 @@ class ContactPage extends BasePage {
46
final TextEditingController _nameController;
47
final TextEditingController _currencyTypeController;
48
final TextEditingController _addressController;
49
+ bool _isEffectsApplied = false;
50
51
@override
52
Widget body(BuildContext context) {
@@ -53,15 +54,7 @@ class ContactPage extends BasePage {
54
color: Theme.of(context).extension<TransactionTradeTheme>()!.detailsTitlesColor,
55
height: 8);
56
56
- reaction((_) => contactViewModel.state, (ExecutionState state) {
57
- if (state is FailureState) {
58
- _onContactSavingFailure(context, state.error);
59
- }
60
-
61
- if (state is ExecutedSuccessfullyState) {
62
- _onContactSavedSuccessfully(context);
63
- }
64
- });
57
+ _setEffects(context);
58
59
return Observer(
60
builder: (_) => ScrollableWithBottomSection(
@@ -177,4 +170,22 @@ class ContactPage extends BasePage {
170
171
void _onContactSavedSuccessfully(BuildContext context) =>
172
Navigator.of(context).pop();
173
+
174
+ void _setEffects(BuildContext context) {
175
+ if (_isEffectsApplied) {
176
+ return;
177
+ }
178
+
179
+ _isEffectsApplied = true;
180
+
181
+ reaction((_) => contactViewModel.state, (ExecutionState state) {
182
+ if (state is FailureState) {
183
+ _onContactSavingFailure(context, state.error);
184
+ }
185
+
186
+ if (state is ExecutedSuccessfullyState) {
187
+ _onContactSavedSuccessfully(context);
188
+ }
189
+ });
190
+ }
191
}