pub struct Actions {
pub key: Option<KeyRef>,
pub dispatcher: Option<ActionDispatcherRef>,
pub actions: HashMap<TypeId, ActionRef>,
pub child: WidgetRef,
}Expand description
A widget that maps Intents to Actions to be used by its descendants when invoking an
Action.
Actions are typically invoked using Shortcuts. They can also be invoked using
Actions::invoke on a context containing an ambient Actions widget.
See also:
Shortcuts, a widget used to bind key combinations toIntents.Intent, a trait for values that contain configuration information for running anAction.Action, a trait for containing and defining an invocation of a user action.ActionDispatcher, the object that this widget uses to manage actions.
Fields§
§key: Option<KeyRef>See Widget::key.
dispatcher: Option<ActionDispatcherRef>The ActionDispatcher object that invokes actions.
This is what is returned from Actions::of, and used by Actions::invoke.
If this dispatcher is None, then Actions::of and
Actions::invoke will look up the tree until they find an Actions widget that has
a dispatcher set. If no such widget is found, then they will return/use a
PlainActionDispatcher.
actions: HashMap<TypeId, ActionRef>A map of Intent types to Action objects that defines which actions this widget
knows about.
For performance reasons, it is recommended that a pre-built map is passed in here instead of defining it inline in the build function.
child: WidgetRefThe widget below this widget in the tree.
Implementations§
Source§impl Actions
impl Actions
Sourcepub fn new<K>(
actions: HashMap<TypeId, ActionRef>,
child: impl IntoWidget<K>,
) -> Actions
pub fn new<K>( actions: HashMap<TypeId, ActionRef>, child: impl IntoWidget<K>, ) -> Actions
Creates an Actions widget.
Sourcepub fn dispatcher(self, dispatcher: ActionDispatcherRef) -> Actions
pub fn dispatcher(self, dispatcher: ActionDispatcherRef) -> Actions
Dart Actions(dispatcher:).
Sourcepub fn handler(
app: &mut App,
context: BuildContext,
intent: IntentRef,
) -> Option<Listener>
pub fn handler( app: &mut App, context: BuildContext, intent: IntentRef, ) -> Option<Listener>
Returns a handler that invokes the bound action for the given intent if the action is
enabled, and returns None if the action is not enabled, or no matching action is
found.
This is intended to be used in widgets which have something similar to an on_tap
handler, which takes a GestureTapCallback, and can be set to the result of calling
this function.
Creates a dependency on the Actions widget that maps the bound action so that if the
actions change, the context will be rebuilt and find the updated action.
The value returned from Action::invoke is discarded when the returned callback is
called. If the return value is needed, consider using Actions::invoke instead.
Sourcepub fn find(
app: &mut App,
context: BuildContext,
intent_type: TypeId,
) -> AnyAction
pub fn find( app: &mut App, context: BuildContext, intent_type: TypeId, ) -> AnyAction
Finds the Action bound to the given intent_type in the given context.
Creates a dependency on the Actions widget that maps the bound action so that if the
actions change, the context will be rebuilt and find the updated action.
If no Actions widget surrounds the given context, or no action is bound to
intent_type, this function panics.
See also:
maybe_find, which is similar to this function, but will returnNoneif noActionsancestor is found.
Sourcepub fn maybe_find(
app: &mut App,
context: BuildContext,
intent_type: TypeId,
) -> Option<AnyAction>
pub fn maybe_find( app: &mut App, context: BuildContext, intent_type: TypeId, ) -> Option<AnyAction>
Finds the Action bound to the given intent_type in the given context.
Creates a dependency on the Actions widget that maps the bound action so that if the
actions change, the context will be rebuilt and find the updated action.
If no Actions widget surrounds the given context, this function returns None.
See also:
Sourcepub fn of(app: &mut App, context: BuildContext) -> ActionDispatcherRef
pub fn of(app: &mut App, context: BuildContext) -> ActionDispatcherRef
Returns the ActionDispatcher associated with the Actions widget that most tightly
encloses the given BuildContext.
Will return a newly created PlainActionDispatcher if no ambient Actions widget is
found.
Sourcepub fn invoke(
app: &mut App,
context: BuildContext,
intent: &dyn Intent,
) -> Option<Rc<dyn Any>>
pub fn invoke( app: &mut App, context: BuildContext, intent: &dyn Intent, ) -> Option<Rc<dyn Any>>
Invokes the action associated with the given Intent using the Actions widget that
most tightly encloses the given BuildContext.
This method returns the result of invoking the action’s Action::invoke method.
If the given intent doesn’t map to an action, then it will look to the next ancestor
Actions widget in the hierarchy until it reaches the root.
This method panics if no ambient Actions widget is found.
Sourcepub fn maybe_invoke(
app: &mut App,
context: BuildContext,
intent: &dyn Intent,
) -> Option<Rc<dyn Any>>
pub fn maybe_invoke( app: &mut App, context: BuildContext, intent: &dyn Intent, ) -> Option<Rc<dyn Any>>
Invokes the action associated with the given Intent using the Actions widget that
most tightly encloses the given BuildContext.
This method returns the result of invoking the action’s Action::invoke method. If no
action mapping was found for the specified intent, or if the first action found was
disabled, or the action itself returns None from Action::invoke, then this method
returns None.
If the given intent doesn’t map to an action, then it will look to the next ancestor
Actions widget in the hierarchy until it reaches the root. If a suitable Action
is found but its AnyAction::is_enabled returns false, the search will stop and this
method will return None.
Trait Implementations§
Source§impl StatefulWidget for Actions
impl StatefulWidget for Actions
Source§type State = ActionsState
type State = ActionsState
Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
debugFillProperties: the properties a dump shows for this widget, in Dart’s
order. Dart’s Widget base only sets the dense tree style, which the framework does.Source§fn create_state(&self) -> ActionsState
fn create_state(&self) -> ActionsState
Source§fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Widget::type_name. A stateful form another widget kind becomes (an animated or
status transition widget) names the widget it wraps.Auto Trait Implementations§
impl !RefUnwindSafe for Actions
impl !Send for Actions
impl !Sync for Actions
impl !UnwindSafe for Actions
impl Forget for Actions
impl Freeze for Actionswhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const RcInner<dyn ActionDispatcher> is !null: Freeze,
PhantomData<RcInner<dyn ActionDispatcher>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<(TypeId, Retained<AnyAction>)>: Freeze,
*const RcInner<dyn Widget> is !null: Freeze,
PhantomData<RcInner<dyn Widget>>: Freeze,
impl Move for Actions
impl Unpin for Actions
impl UnsafeUnpin for Actionswhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn ActionDispatcher> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn ActionDispatcher>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<(TypeId, Retained<AnyAction>)>: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.