SelectionContainer class Null safety

A container that handles SelectionEvents for the Selectables in the subtree.

This widget is useful when one wants to customize selection behaviors for a group of Selectables

The state of this container is a single selectable and will register itself to the registrar if provided. Otherwise, it will register to the SelectionRegistrar from the context.

The containers handle the SelectionEvents from the registered SelectionRegistrar and delegate the events to the delegate.

This widget uses SelectionRegistrarScope to host the delegate as the SelectionRegistrar for the subtree to collect the Selectables, and SelectionEvents received by this container are sent to the delegate using the SelectionHandler API of the delegate.

This sample demonstrates how to create a SelectionContainer that only allows selecting everything or nothing with no partial selection.
To create a local project with this code sample, run:
flutter create --sample=widgets.SelectionContainer.1 mysample

See also:



SelectionContainer({Key? key, SelectionRegistrar? registrar, required SelectionContainerDelegate delegate, required Widget child})
Creates a selection container to collect the Selectables in the subtree.
SelectionContainer.disabled({Key? key, required Widget child})
Creates a selection container that disables selection for the subtree.


child Widget
This widget can only have one child. To lay out multiple children, let this widget's child be a widget such as Row, Column, or Stack, which have a children property, and then provide the children to that widget.
delegate SelectionContainerDelegate?
The delegate for SelectionEvents sent to this selection container.
hashCode int
The hash code for this object.
@nonVirtual, read-only, inherited
key Key?
Controls how one widget replaces another widget in the tree.
final, inherited
registrar SelectionRegistrar?
The SelectionRegistrar this container is registered to.
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


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


operator ==(Object other) bool
The equality operator.
@nonVirtual, inherited

Static Methods

maybeOf(BuildContext context) SelectionRegistrar?
Gets the immediate ancestor SelectionRegistrar of the BuildContext.