Skip to content

Commit a9a6a63

Browse files
authored
fix(web): prevent Focus exception after feedback submission and window restore (#359)
* Fix Focus exception in web This hotfix addresses a Focus exception that occurs on the Web platform when a user submits feedback and then hides/restores the browser window. The issue stems from a focus context being accessed before it's properly attached. * fix(keyboard): improve keyboard hiding logic with focus check Refactored _hideKeyboard method to use FocusScope.of(context).unfocus() only when there's an active focus that is not the primary focus. This is more precise than calling requestFocus(FocusNode()), which can cause issues like: Attaching a focus node without context may throw runtime exceptions. It introduces unnecessary focus traversal, which may lead to unexpected behavior in complex focus trees. unfocus() is a cleaner, Flutter-recommended way to dismiss the keyboard. This approach safely checks focus state and dismisses the keyboard only when appropriate, avoiding crashes and unwanted side effects.
1 parent 894e7d1 commit a9a6a63

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

feedback/lib/src/feedback_widget.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,11 @@ class FeedbackWidgetState extends State<FeedbackWidget>
353353
}
354354

355355
static void _hideKeyboard(BuildContext context) {
356-
FocusScope.of(context).requestFocus(FocusNode());
356+
final currentFocus = FocusScope.of(context);
357+
358+
if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
359+
currentFocus.unfocus();
360+
}
357361
}
358362
}
359363

0 commit comments

Comments
 (0)