PersistentSafeArea constructor
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 totrue. -
top— Whether to apply the system safe area padding on the top side. Defaults totrue. -
right— Whether to apply the system safe area padding on the right side. Defaults totrue. -
bottom— Whether to apply the system safe area padding on the bottom side. Defaults totrue. -
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 callPersistentSafeAreaBottom.startObservingSafeAreaandPersistentSafeAreaBottom.stopObservingSafeAreato manage lifecycle.
- If
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,
});