useAutomaticKeepAlive top-level property
_UseAutomaticKeepAliveCreator
useAutomaticKeepAlive
final
Hook for controlling widget keep-alive behavior.
This hook allows you to prevent widgets from being disposed when they're scrolled out of view, which is useful for expensive widgets that should maintain their state (e.g., in PageView, ListView, or TabBarView).
Use call for static boolean values, or value for reactive values.
Example:
@override
setup(context, props) {
// Static value
useAutomaticKeepAlive(true);
// Or reactive value
final keepAlive = useSignal(true);
useAutomaticKeepAlive.value(keepAlive);
return () => MyExpensiveWidget();
}
Implementation
final useAutomaticKeepAlive = _UseAutomaticKeepAliveCreator._();