diff --git a/packages/stripe/lib/src/widgets/keep_visible_on_focus.dart b/packages/stripe/lib/src/widgets/keep_visible_on_focus.dart index 233bd4d27..eb7143d51 100644 --- a/packages/stripe/lib/src/widgets/keep_visible_on_focus.dart +++ b/packages/stripe/lib/src/widgets/keep_visible_on_focus.dart @@ -30,11 +30,14 @@ class _KeepVisibleOnFocusState extends State } void onFocusChanged() { - if (widget.focusNode.hasFocus) { + if (widget.focusNode.hasFocus && !_isObserverRegistered) { WidgetsBinding.instance.addObserver(this); _lastBottomViewInset = MediaQuery.of(context).viewInsets.bottom; + _isObserverRegistered = true; + } else { WidgetsBinding.instance.removeObserver(this); + _isObserverRegistered = false; } } @@ -42,6 +45,8 @@ class _KeepVisibleOnFocusState extends State bool _showOnScreenScheduled = false; + bool _isObserverRegistered = false; + void _showOnScreen() { if (_showOnScreenScheduled) { return; @@ -79,3 +84,4 @@ class _KeepVisibleOnFocusState extends State super.dispose(); } } +