• Greg Spencer's avatar
    Allow requestFocus on an unattached FocusNode to create a deferred focus request (#48589) · 6495d377
    Greg Spencer authored
    This changes the behavior of requestFocus when it is called on a FocusNode that does not yet have a parent, so that it defers requesting focus until it receives a parent. Before this change, calling requestFocus before it had a parent was a no-op.
    
    This allows scenarios where a widget is newly added and wishes to immediately request the focus. Previously, it was very hard to make that work because requesting focus before the widget's focus node had a parent was ignored, so the developer had to wait until two frames later to request focus (one for the widget's node to be added to the focus tree, and one to request the focus).
    
    Now, in order to have a widget be focused when initially added, you just need to call requestFocus on its node when you create it, and as soon as it is added, it will automatically request focus.
    
    This is different from the autofocus attribute on the Focus widget, because it unconditionally requests focus when added (autofocus will only request focus if nothing else in the scope has focus).
    6495d377
Name
Last commit
Last update
.github Loading commit data...
bin Loading commit data...
dev Loading commit data...
examples Loading commit data...
packages Loading commit data...
.cirrus.yml Loading commit data...
.codecov.yml Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CODEOWNERS Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
CONTRIBUTING.md Loading commit data...
LICENSE Loading commit data...
PATENT_GRANT Loading commit data...
README.md Loading commit data...
analysis_options.yaml Loading commit data...
dartdoc_options.yaml Loading commit data...
flutter_console.bat Loading commit data...