The Visibility widget is no longer focusable by default when maintainState is enabled
Summary
#This change was introduced to fix an issue
where an IndexedStack
s hidden children would be focusable with keyboard events
(see issue)
due to the underlying Visibility
widgets default behavior.
Description of change
#The core change is the Visibility
widget is no longer focusable by default
when maintainState
is enabled.
A new flag, maintainFocusability
, must be set to true with maintainState
for a hidden widget to remain focusable.
Migration guide
#If your app has a Visibility
widget that does not set maintainState
to true,
then no changes are required.
If your app has a Visibility
widget that sets maintainState
to true
and you relied on the previous default behavior
that allowed you to focus your hidden widget,
you will need to set maintainFocusability
to true.
Code before migration:
child: Visibility(
maintainState: true,
child: SomeWidget(),
)
Code after migration:
child: Visibility(
maintainState: true,
maintainFocusability: true,
child: SomeWidget(),
)
Timeline
#Landed in version: 3.34.0-pre
In stable release: 3.35
References
#API documentation:
Relevant issues:
Relevant PRs:
除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2025-10-02。 查看文档源码 或者 为本页面内容提出建议.