PersistentSafeArea class

A widget that insets its child by the current safe area padding (such as the home indicator or navigation bar) which stays stable during keyboard animations.

Unlike Flutter’s built-in SafeArea, this widget ensures the bottom inset remains stable during keyboard animations.

It listens to the PersistentSafeAreaBottom.notifier notifier to apply the correct bottom padding dynamically.


Example

PersistentSafeArea(
  child: Scaffold(
    backgroundColor: Colors.black,
    body: Center(child: Text('Safe content area')),
  ),
)

Lifecycle Handling

By default, the widget doesn't start and stop observing native safe area changes automatically when it’s inserted or removed from the widget tree.

You must manage the observation manually (for example, via PersistentSafeAreaBottom.startObservingSafeArea() in your own lifecycle), to prevent duplicate observers or set handleObserver to true and let this widget handle it automatically.


Parameters

  • child — The widget below this widget in the tree.
  • handleObserver — Whether the widget should automatically start and stop native safe area observation. Defaults to false.

When handleObserver is false, you must manage the lifecycle manually:

@override
void initState() {
  super.initState();
  PersistentSafeAreaBottom.startObservingSafeArea();
}

@override
void dispose() {
  PersistentSafeAreaBottom.stopObservingSafeArea();
  super.dispose();
}
Inheritance

Constructors

PersistentSafeArea({required Widget child, bool left = true, bool top = true, bool right = true, bool bottom = true, bool handleObserver = false, EdgeInsets minimum = EdgeInsets.zero, Key? key})
Creates a widget that insets its child by the system safe area padding, keeping the bottom inset stable during keyboard animations.
const

Properties

bottom bool
Whether to avoid system intrusions on the bottom side of the screen.
final
child Widget
The widget below this widget in the tree.
final
handleObserver bool
Whether to automatically manage the lifecycle of the PersistentSafeAreaBottom observer.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
left bool
Whether to avoid system intrusions on the left.
final
minimum EdgeInsets
This minimum padding to apply.
final
Whether to avoid system intrusions on the right.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
top bool
Whether to avoid system intrusions at the top of the screen, typically the system status bar.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<PersistentSafeArea>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited