-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Use case
I had a strange bug where when i closed the ModalBottomSheet/Dialog, it would focus my Autocomplete, which i've designed to open the results box on focus. So it would open the search box after closing the dialog/bottomsheet.
I realise most people won't have that form control, but still, man it was hard to find out what was focusing it, and i'm sure some other people don't want their first control focused upon dialog/bottomsheet close.
I found out it was this code inside routes.dart, and can be turned off by setting shouldRequestFocus to false.
// This should be called to wrap any changes to route.isCurrent, route.canPop,
// and route.offstage.
void _routeSetState(VoidCallback fn) {
if (widget.route.isCurrent && !_shouldIgnoreFocusRequest && _shouldRequestFocus) {
widget.route.navigator!.focusNode.enclosingScope?.setFirstFocus(focusScopeNode);
}
setState(fn);
}
ModalBottomSheetRoute accepts a requestFocus param which Future<T?> showModalBottomSheet<T>({ instantiates, but showModalBottomSheet doesn't have requestFocus as a param.
Proposal
Add requestFocus to showModalBottomSheet and all other types of popups that may want the same treatment (dialogs at the least).