File tree Expand file tree Collapse file tree 1 file changed +25
-5
lines changed
packages/stripe_web/lib/src/widgets Expand file tree Collapse file tree 1 file changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -169,15 +169,35 @@ class PaymentElementState extends State<PaymentElement> {
169
169
final FocusNode _focusNode = FocusNode (debugLabel: 'CardField' );
170
170
FocusNode get _effectiveNode => widget.focusNode ?? _focusNode;
171
171
172
+ bool _isManuallyFocusing = false ; // Track manual focus/blur actions
173
+ bool _isCurrentlyFocused = false ; // Track current focus state
174
+
172
175
@override
173
176
Widget build (BuildContext context) {
174
177
return Focus (
175
178
focusNode: _effectiveNode,
176
- onFocusChange: (focus) {
177
- /* if (focus)
178
- element?.focus();
179
- else
180
- element?.blur(); */
179
+ onFocusChange: (focus) {
180
+ // Prevent feedback loop from manual focus/blur actions
181
+ if (_isManuallyFocusing) {
182
+ _isManuallyFocusing = false ;
183
+ return ;
184
+ }
185
+
186
+ // Check if the focus state has actually changed
187
+ if (_isCurrentlyFocused == focus) {
188
+ return ; // No state change, do nothing
189
+ }
190
+
191
+ // Update the current focus state
192
+ _isCurrentlyFocused = focus;
193
+
194
+ if (focus) {
195
+ _isManuallyFocusing = true ;
196
+ element? .focus ();
197
+ } else {
198
+ _isManuallyFocusing = true ;
199
+ element? .blur ();
200
+ }
181
201
},
182
202
child: ConstrainedBox (
183
203
constraints: BoxConstraints (
You can’t perform that action at this time.
0 commit comments