Action<T extends Intent>.overridable constructor
Null safety
- {required Action<
T> defaultAction, - required BuildContext context}
Creates an Action that allows itself to be overridden by the closest
ancestor Action in the given context
that handles the same Intent,
if one exists.
When invoked, the resulting Action tries to find the closest Action in
the given context
that handles the same type of Intent as the
defaultAction
, then calls its Action.invoke method. When no override
Actions can be found, it invokes the defaultAction
.
An overridable action delegates everything to its override if one exists,
and has the same behavior as its defaultAction
otherwise. For this
reason, the override has full control over whether and how an Intent
should be handled, or a key event should be consumed. An override
Action's callingAction property will be set to the Action it
currently overrides, giving it access to the default behavior. See the
callingAction property for an example.
The context
argument is the BuildContext to find the override with. It
is typically a BuildContext above the Actions widget that contains
this overridable Action.
The defaultAction
argument is the Action to be invoked where there's
no ancestor Actions can't be found in context
that handle the same
type of Intent.
This is useful for providing a set of default Actions in a leaf widget to allow further overriding, or to allow the Intent to propagate to parent widgets that also support this Intent.
flutter create --sample=widgets.Action.overridable.1 mysample
Implementation
factory Action.overridable({
required Action<T> defaultAction,
required BuildContext context,
}) {
return defaultAction._makeOverridableAction(context);
}