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
flutter create --sample=widgets.SelectionContainer.1 mysample
See also:
- SelectableRegion, which provides an overview of the selection system.
- SelectionContainer.disabled, which disable selection for a subtree.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- SelectionContainer
Constructors
- SelectionContainer({Key? key, SelectionRegistrar? registrar, required SelectionContainerDelegate delegate, required Widget child})
-
Creates a selection container to collect the Selectables in the subtree.
const
- SelectionContainer.disabled({Key? key, required Widget child})
-
Creates a selection container that disables selection for the
subtree.
const
Properties
- 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.final - delegate → SelectionContainerDelegate?
-
The delegate for SelectionEvents sent to this selection container.
final
- hashCode → int
- The hash code for this object.
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- registrar → SelectionRegistrar?
-
The SelectionRegistrar this container is registered to.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
read-onlyinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< SelectionContainer> -
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.protected">@protectedinherited -
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent 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}) → 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.
nonVirtual">@nonVirtualinherited
Static Methods
-
maybeOf(
BuildContext context) → SelectionRegistrar? - Gets the immediate ancestor SelectionRegistrar of the BuildContext.