SheetPopScope<T> class
Manages the back navigation gesture for the current modal sheet.
This widget is a wrapper around PopScope, providing additional control over the swipe-to-dismiss gesture in a modal sheet. The behavior of the modal sheet is determined by the canPop property and whether onPopInvokedWithResult is provided. The table below describes how the sheet behaves based on these properties:
| Behavior | Implementation |
|---|---|
| Can pop; Gesture is enabled | SheetPopScope(canPop: true) |
| Cannot pop; Gesture is enabled | SheetPopScope(canPop: false, onPopInvokedWithResult: nonNullCallback) |
| Cannot pop; Gesture is disabled | SheetPopScope(canPop: false, onPopInvokedWithResult: null) |
Note that the gesture is always disabled if ModalSheetRouteMixin.swipeDismissible on the parent route is false.
Typically, this widget is placed above a sheet widget:
ModalSheetRoute(
swipeDismissible: true,
builder: (context) => SheetPopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) {...},
child: Sheet(child: Container()),
),
);
However, it can also be placed deeper within the sheet's widget tree. This is useful when you want to dynamically control gesture availability in a widget's build method:
class SheetContent extends StatelessWidget {
@override
Widget build(BuildContext context) {
// If false, the modal cannot be popped, and the gesture is also disabled
// (and vice versa).
final canPopByGesture = ...;
return SheetPopScope(
canPop: canPopByGesture,
onPopInvokedWithResult: canPopByGesture
? (didPop, result) {...}
: null,
child: Sheet(child: Container()),
);
}
}
Compatibility with PopScope
While SheetPopScope offers fine-grained control, the standard PopScope widget can also manage a modal sheet's dismissibility. However, PopScope lacks the ability to control the swipe-to-dismiss gesture.
Assuming ModalSheetRouteMixin.swipeDismissible is true, PopScope
behaves similarly to SheetPopScope in the following cases:
| Behavior | Implementation |
|---|---|
| Can pop; Gesture is enabled | PopScope(canPop: true) |
| Cannot pop; Gesture is enabled | PopScope(canPop: false) |
| Cannot pop; Gesture is disabled | ❌ Not possible |
Note that the first two cases are equivalent to SheetPopScope, but the third is not possible with PopScope.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- SheetPopScope
Constructors
-
SheetPopScope({required Widget child, Key? key, bool canPop = true, PopInvokedWithResultCallback<
T> ? onPopInvokedWithResult}) -
Creates a widget that controls the pop behavior of a modal sheet.
const
Properties
- canPop → bool
-
When false, blocks the current route from being popped.
final
- child → Widget
-
The widget below this widget in the tree.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
onPopInvokedWithResult
→ PopInvokedWithResultCallback<
T> ? -
A callback that is called when a pop is attempted on the current route,
including when the swipe gesture is performed.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< SheetPopScope< T> > -
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