# The Visibility widget is no longer focusable by default when maintainState is enabled

> The Visibility widget by default no longer implicitly retains focusability for its child when maintainState is enabled.




:::important
These breaking change docs are accurate, as of the release
under which they are published. Over time, the
workarounds described here might become inaccurate.
We don't, in general, keep these breaking change docs up
to date as of each release.

这些破坏性改动文档的准确性仅限于其发布时对应的版本。
随着时间的推移，文档中描述的方案可能会逐渐失效。
通常情况下，我们不会在每次发布新版本时都对这些文档进行同步更新。

The [breaking change index file](/release/breaking-changes)
lists the docs created for each release.

[破坏性改动列表](/release/breaking-changes) 
列出了每个版本的文档。

:::


## Summary
This change was introduced to fix an issue
where an `IndexedStack`s hidden children would be focusable with keyboard events
(see [issue](https://github.com/flutter/flutter/issues/114213))
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:

```dart
child: Visibility(
    maintainState: true,
    child: SomeWidget(),
)
```

Code after migration:

```dart
child: Visibility(
    maintainState: true,
    maintainFocusability: true,
    child: SomeWidget(),
)
```

## Timeline

Landed in version: 3.34.0-pre<br>
In stable release: 3.35

## References

API documentation:

* [`Visibility`](https://api.flutter-io.cn/flutter/widgets/Visibility-class.html)

Relevant issues:

* [Issue 114213](https://github.com/flutter/flutter/issues/114213)

Relevant PRs:

* [PR 159133: Add flag to exclude focus for hidden children in Visibility, maintainFocusability. Set maintainFocusability to false in IndexedStack](https://github.com/flutter/flutter/pull/159133)

