PersistentSafeArea constructor

const PersistentSafeArea({
  1. required Widget child,
  2. bool left = true,
  3. bool top = true,
  4. bool right = true,
  5. bool bottom = true,
  6. bool handleObserver = false,
  7. EdgeInsets minimum = EdgeInsets.zero,
  8. Key? key,
})

Creates a widget that insets its child by the system safe area padding, keeping the bottom inset stable during keyboard animations.

This constructor behaves similarly to Flutter’s SafeArea widget, but uses native platform observers to provide more consistent layout behavior when the keyboard is shown or hidden.


Behavior

  • Uses a ValueNotifier to track the bottom safe area in real time.
  • Remains stable while the keyboard animates in or out.
  • Updates automatically on system layout changes (e.g., orientation or navigation mode).
  • Can optionally manage native observer lifecycle automatically via handleObserver.

Parameters

  • child — The widget below this widget in the tree.

  • left — Whether to apply the system safe area padding on the left side. Defaults to true.

  • top — Whether to apply the system safe area padding on the top side. Defaults to true.

  • right — Whether to apply the system safe area padding on the right side. Defaults to true.

  • bottom — Whether to apply the system safe area padding on the bottom side. Defaults to true.

  • minimum — The minimum padding to apply on each side, even if the system inset for that side is smaller. Defaults to EdgeInsets.zero.

  • handleObserver — Whether the widget should automatically start and stop observing the native safe area changes.

    • If true, observation starts when this widget is inserted into the tree, and stops when it’s removed.
    • If false (default), you must manually call PersistentSafeAreaBottom.startObservingSafeArea and PersistentSafeAreaBottom.stopObservingSafeArea to manage lifecycle.

Example

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

Implementation

const PersistentSafeArea({
  required this.child,
  this.left = true,
  this.top = true,
  this.right = true,
  this.bottom = true,
  this.handleObserver = false,
  this.minimum = EdgeInsets.zero,
  super.key,
});