Skip to main content

AnyElement

Struct AnyElement 

Source
pub struct AnyElement { /* private fields */ }
Expand description

Erased Element: one identity and a static vtable, like AnyRenderObject.

Equality is Dart’s == on an element, which is identity.

Implementations§

Source§

impl AnyElement

Source

pub fn id(self) -> HandleId

The arena id behind this handle.

Source

pub fn downcast<T: Element>(self, app: &App) -> Option<Handle<T>>

Dart’s element as T: the typed handle when this element is a T, else None.

Source

pub fn widget(self, app: &App) -> &WidgetRef

The configuration for this element.

Avoid overriding this field on Element subtypes.

Source

pub fn mounted(self, app: &App) -> bool

Returns true if the Element is active.

A defunct element is freed after its unmount; a handle kept past that, as a callback keeps its BuildContext, answers false.

Source

pub fn parent(self, app: &App) -> Option<AnyElement>

The parent of this element, or None at the root.

Source

pub fn slot(self, app: &App) -> Option<Slot>

Information set by parent to define where this child fits in its parent’s child list.

Source

pub fn depth(self, app: &App) -> u32

An integer that is guaranteed to be greater than the parent’s, if any. The element at the root of the tree must have a depth greater than 0.

Source

pub fn owner(self, app: &App) -> Option<Handle<BuildOwner>>

The object that manages the lifecycle of this element.

Source

pub fn build_scope(self, app: &App) -> Handle<BuildScope>

The BuildScope whose dirty list this element is in.

Source

pub fn lifecycle(self, app: &App) -> ElementLifecycle

Where this element is in its lifecycle; a freed element is defunct.

Source

pub fn to_string_short(self, app: &App) -> String

Dart’s toStringShort: the widget’s, or the element’s identity once it has none.

Source

pub fn to_diagnostics_node( self, app: &App, name: impl IntoPropertyName, ) -> ElementDiagnosticsNode

Dart’s toDiagnosticsNode(name:): a snapshot of this element and its descendants as a dump shows them, one line each in the dense style.

Source

pub fn to_string_deep(self, app: &App) -> String

Dart’s Element.toStringDeep: this element and its descendants, at Dart’s default level (debug) and width.

Source

pub fn to_string_deep_with( self, app: &App, min_level: DiagnosticLevel, wrap_width: usize, ) -> String

to_string_deep showing only properties at min_level or above, wrapping a line at wrap_width characters.

Source

pub fn debug_is_active(self, app: &App) -> bool

Whether the element is active (in the tree).

Source

pub fn debug_is_defunct(self, app: &App) -> bool

Whether the element is defunct (unmounted).

Source

pub fn dirty(self, app: &App) -> bool

Returns true if the element has been marked as needing rebuilding.

The flag is true when the element is first created and after mark_needs_build has been called. The flag is reset to false in the perform_rebuild implementation.

Source

pub fn debug_doing_build(self, app: &App) -> bool

Whether this element is in the middle of building.

Source

pub fn children(self, app: &App) -> Vec<AnyElement>

The children, in visit order.

Source

pub fn visit_children(self, app: &App, visitor: &mut dyn FnMut(AnyElement))

Source

pub fn debug_visit_onstage_children( self, app: &App, visitor: &mut dyn FnMut(AnyElement), )

Source

pub fn descendants(self, app: &App, skip_offstage: bool) -> Vec<AnyElement>

Every element under this one, depth first with a parent before its children and siblings in order, without this one, and with skip_offstage only those onstage: Dart’s collectAllElementsFrom.

Source

pub fn render_object_attaching_child(self, app: &App) -> Option<AnyElement>

Source

pub fn mount( self, app: &mut App, parent: Option<AnyElement>, new_slot: Option<Slot>, )

Source

pub fn update(self, app: &mut App, new_widget: WidgetRef)

Source

pub fn update_slot(self, app: &mut App, new_slot: Option<Slot>)

Source

pub fn attach_render_object(self, app: &mut App, new_slot: Option<Slot>)

Source

pub fn detach_render_object(self, app: &mut App)

Source

pub fn forget_child(self, app: &mut App, child: AnyElement)

Source

pub fn activate(self, app: &mut App)

Source

pub fn deactivate(self, app: &mut App)

Source

pub fn debug_deactivated(self, app: &mut App)

Source

pub fn unmount(self, app: &mut App)

Source

pub fn perform_rebuild(self, app: &mut App)

Source

pub fn did_change_dependencies(self, app: &mut App)

Source

pub fn update_inheritance(self, app: &mut App)

Source

pub fn attach_notification_tree(self, app: &mut App)

Source

pub fn on_notification( self, app: &mut App, notification: &dyn Notification, ) -> bool

Source

pub fn dispatch_notification( self, app: &mut App, notification: &dyn Notification, )

Start bubbling this notification at the given build context.

The notification will be delivered to any NotificationListener widgets with the appropriate type parameters that are ancestors of the given BuildContext.

Source

pub fn debug_expects_render_object_for_slot( self, app: &App, slot: Option<&Slot>, ) -> bool

Source

pub fn render_object(self, app: &App) -> Option<AnyRenderObject>

The render object at (or below) this location in the tree.

If this object is a RenderObjectElement, the render object is the one at this location in the tree. Otherwise, this getter will walk down the tree until it finds a RenderObjectElement.

Some locations in the tree are not backed by a render object. In those cases, this getter returns None.

Source

pub fn inflate_widget( self, app: &mut App, new_widget: WidgetRef, new_slot: Option<Slot>, ) -> AnyElement

Element.inflateWidget: create an element for the given widget and add it as a child of this element in the given slot.

Source

pub fn is_render_object_element(self) -> bool

Dart’s this is RenderObjectElement.

Source

pub fn insert_render_object_child( self, app: &mut App, child: AnyRenderObject, slot: Option<Slot>, )

Source

pub fn move_render_object_child( self, app: &mut App, child: AnyRenderObject, old_slot: Option<Slot>, new_slot: Option<Slot>, )

Source

pub fn remove_render_object_child( self, app: &mut App, child: AnyRenderObject, slot: Option<Slot>, )

Source

pub fn update_parent_data(self, app: &mut App, parent_data_element: AnyElement)

Source

pub fn is_parent_data_element(self) -> bool

Dart’s this is ParentDataElement.

Source

pub fn apply_parent_data( self, app: &mut App, render_object: AnyRenderObject, ) -> bool

Source

pub fn is_inherited_element(self) -> bool

Dart’s this is InheritedElement.

Source

pub fn update_dependencies( self, app: &mut App, dependent: AnyElement, aspect: Option<Rc<dyn Any>>, )

Source

pub fn remove_dependent(self, app: &mut App, dependent: AnyElement)

Source

pub fn state_handle<S: State>(self, app: &App) -> Option<Handle<S>>

The typed state handle when this is a StatefulElement whose state is an S.

Source

pub fn update_child( self, app: &mut App, child: Option<AnyElement>, new_widget: Option<WidgetRef>, new_slot: Option<Slot>, ) -> Option<AnyElement>

Update the given child with the given new configuration.

This method is the core of the widgets system. It is called each time we are to add, update, or remove a child based on an updated configuration.

The new_slot argument specifies the new value for this element’s slot.

If the child is None, and the new_widget is not None, then we have a new child for which we need to create an Element, configured with new_widget.

If the new_widget is None, and the child is not None, then we need to remove it because it no longer has a configuration.

If neither are None, then we need to update the child’s configuration to be the new configuration given by new_widget. If new_widget can be given to the existing child (as determined by can_update), then it is so given. Otherwise, the old child needs to be disposed and a new child created for the new configuration.

If both are None, then we don’t have a child and won’t have a child, so we do nothing.

The update_child method returns the new child, if it had to create one, or the child that was passed in, if it just had to update the child, or None, if it removed the child and did not replace it.

Source

pub fn update_children( self, app: &mut App, old_children: &[AnyElement], new_widgets: &[WidgetRef], forgotten_children: Option<ForgottenChildren<'_>>, slots: Option<&[Option<Slot>]>, ) -> Vec<AnyElement>

Updates the children of this element to use new widgets.

Attempts to update the given old children list using the given new widgets, removing obsolete elements and introducing new ones as necessary, and then returns the new child list.

During this function the old_children list must not be modified. If the caller wishes to remove elements from old_children reentrantly while this function is on the stack, the caller can supply a forgotten_children argument, which can be modified while this function is on the stack. Whenever this function reads from old_children, this function first checks whether the child is in forgotten_children. If it is, the function acts as if the child was not in old_children.

forgotten_children is a predicate so that it reads the caller’s set live (in the arena, where a reentrant forget_child writes it) rather than a snapshot.

This function is a convenience wrapper around update_child, which updates each individual child. If slots is non-None, the value for the new_slot argument of update_child is retrieved from that list using the index that the currently processed child corresponds to in the new_widgets list (new_widgets and slots must have the same length). If slots is None, an IndexedSlot is used as the value for the new_slot argument. In that case, IndexedSlot::index is set to the index that the currently processed child corresponds to in the new_widgets list and IndexedSlot::value is set to the Element of the previous widget in that list (or None if it is the first child).

Source

pub fn update_slot_for_child( self, app: &mut App, child: AnyElement, new_slot: Option<Slot>, )

Change the slot that the given child occupies in its parent.

Called by MultiChildRenderObjectElement, and other RenderObjectElement subclasses that have multiple children, when child moves from one position to another in this element’s child list.

Source

pub fn deactivate_child(self, app: &mut App, child: AnyElement)

Move the given element to the list of inactive elements and detach its render object from the render tree.

This method stops the given element from being a child of this element by detaching its render object from the render tree and moving the element to the list of inactive elements.

This method (indirectly) calls deactivate on the child.

The caller is responsible for removing the child from its child model. Typically deactivate_child is called by the element itself while it is updating its child model; however, during GlobalKey reparenting, the new parent proactively calls the old parent’s deactivate_child, first using forget_child to cause the old parent to update its child model.

Source

pub fn find_render_object(self, app: &App) -> Option<AnyRenderObject>

The current RenderObject for the widget. If the widget is a RenderObjectWidget, this is the render object that the widget created for itself. Otherwise, it is the render object of the first descendant RenderObjectWidget.

This method will only return a valid result after the build phase is complete. It is therefore not valid to call this from a build method. It should only be called from interaction event handlers (e.g. gesture callbacks) or layout or paint callbacks. It is also not valid to call if mounted is false.

Source

pub fn size(self, app: &App) -> Option<Size>

The size of the RenderBox returned by find_render_object.

This getter will only return a valid result after the layout phase is complete. It is therefore not valid to call this from a build method. It should only be called from paint callbacks or interaction event handlers (e.g. gesture callbacks).

This getter will only return a valid result if find_render_object actually returns a RenderBox. If find_render_object returns a render object that is not a subtype of RenderBox (e.g., RenderView), this getter will return None.

Source

pub fn does_depend_on_inherited_element( self, app: &App, ancestor: AnyElement, ) -> bool

Returns true if ancestor is a dependency of this element.

Source

pub fn depend_on_inherited_element( self, app: &mut App, ancestor: AnyElement, aspect: Option<Rc<dyn Any>>, ) -> WidgetRef

Registers this build context with ancestor such that when ancestor’s widget changes this build context is rebuilt.

Returns ancestor.widget.

This method is rarely called directly. Most applications should use depend_on_inherited_widget_of_exact_type, which calls this method after finding the appropriate InheritedElement ancestor.

Source

pub fn depend_on_inherited_widget_of_exact_type<W: InheritedWidget>( self, app: &mut App, ) -> Option<&W>

Returns the nearest widget of the given type W and creates a dependency on it, or None if no appropriate widget is found.

The widget found will be a concrete InheritedWidget subclass, and calling this method registers this build context with the returned widget. When that widget changes (or a new widget of that type is introduced, or the widget goes away), this build context is rebuilt so that it can obtain new values from that widget.

This is typically called implicitly from of() static methods, e.g. Theme.of.

This method should not be called from widget constructors or from State::init_state methods, because those methods would not get called again if the inherited value were to change. To ensure that the widget correctly updates itself when the inherited value changes, only call this (directly or indirectly) from build methods, layout and paint callbacks, or from State::did_change_dependencies.

Source

pub fn depend_on_inherited_widget_of_exact_type_with_aspect<W: InheritedWidget>( self, app: &mut App, aspect: Option<Rc<dyn Any>>, ) -> Option<&W>

depend_on_inherited_widget_of_exact_type with Dart’s aspect argument, for InheritedModel.

Source

pub fn get_inherited_widget_of_exact_type<W: InheritedWidget>( self, app: &App, ) -> Option<&W>

Returns the nearest widget of the given InheritedWidget subclass W or None if an appropriate ancestor is not found.

This method does not introduce a dependency the way that the more typical depend_on_inherited_widget_of_exact_type does, so this context will not be rebuilt if the InheritedWidget changes. This function is meant for those uncommon use cases where a dependency is undesirable.

Source

pub fn get_element_for_inherited_widget_of_exact_type<W: InheritedWidget>( self, app: &App, ) -> Option<AnyElement>

Obtains the element corresponding to the nearest widget of the given type W, which must be the type of a concrete InheritedWidget subclass.

Returns None if no such element is found.

Calling this method is O(1) with a small constant factor.

This method does not establish a relationship with the target in the way that depend_on_inherited_widget_of_exact_type does.

Source

pub fn find_ancestor_widget_of_exact_type<W: 'static>( self, app: &App, ) -> Option<&W>

Returns the nearest ancestor widget of the given type W, which must be the type of a concrete Widget subclass.

In general, depend_on_inherited_widget_of_exact_type is more useful, since inherited widgets will trigger consumers to rebuild when they change. This method is appropriate when used in interaction event handlers (e.g. gesture callbacks) or for performing one-off tasks such as asserting that you have or don’t have a widget of a specific type as an ancestor. The return value of a Widget’s build method should not depend on the value returned by this method, because the build context will not rebuild if the return value of this method changes. This could lead to a situation where data used in the build method changes, but the widget is not rebuilt.

Calling this method is relatively expensive (O(N) in the depth of the tree). Only call this method if the distance from this widget to the desired ancestor is known to be small and bounded.

Source

pub fn find_ancestor_state_of_type<S: State>( self, app: &App, ) -> Option<Handle<S>>

Returns the State object of the nearest ancestor StatefulWidget widget that is an instance of the given type S.

This should not be used from build methods, because the build context will not be rebuilt if the value that would be returned by this method changes. In general, depend_on_inherited_widget_of_exact_type is more appropriate for such cases. This method is useful for changing the state of an ancestor widget in a one-off manner, for example, to cause an ancestor scrolling list to scroll this build context’s widget into view, or to move the focus in response to user interaction.

Calling this method is relatively expensive (O(N) in the depth of the tree). Only call this method if the distance from this widget to the desired ancestor is known to be small and bounded.

Source

pub fn find_root_ancestor_state_of_type<S: State>( self, app: &App, ) -> Option<Handle<S>>

Returns the State object of the furthest ancestor StatefulWidget widget that is an instance of the given type S.

Functions the same way as find_ancestor_state_of_type but keeps visiting subsequent ancestors until there are none of the type instance of S remaining. Then returns the last one found.

This operation is O(N) as well though N is the entire widget tree rather than a subtree.

Source

pub fn find_ancestor_render_object_of_type<R: RenderObject>( self, app: &App, ) -> Option<RenderHandle<R>>

Returns the RenderObject object of the nearest ancestor RenderObjectWidget widget that is an instance of the given type R.

This should not be used from build methods, because the build context will not be rebuilt if the value that would be returned by this method changes. In general, depend_on_inherited_widget_of_exact_type is more appropriate for such cases. This method is useful only in esoteric cases where a widget needs to cause an ancestor to change its layout or paint behavior. For example, it is used by Material so that InkWell widgets can trigger the ink splash on the Material’s actual render object.

Calling this method is relatively expensive (O(N) in the depth of the tree). Only call this method if the distance from this widget to the desired ancestor is known to be small and bounded.

Source

pub fn visit_ancestor_elements( self, app: &App, visitor: &mut dyn FnMut(AnyElement) -> bool, )

Walks the ancestor chain, starting with the parent of this build context’s widget, invoking the argument for each ancestor.

The callback is given a reference to the ancestor widget’s corresponding Element object. The walk stops when it reaches the root widget or when the callback returns false. The callback must not return None.

This is useful for inspecting the widget tree.

Calling this method is relatively expensive (O(N) in the depth of the tree).

Source

pub fn visit_child_elements( self, app: &App, visitor: &mut dyn FnMut(AnyElement), )

Walks the children of this widget.

This is useful for applying changes to children after they are built without waiting for the next frame, especially if the children are known, and especially if there is exactly one child (as is always the case for StatefulWidgets or StatelessWidgets).

Calling this method is very cheap for build contexts that correspond to StatefulWidgets or StatelessWidgets (O(1), since there’s only one child).

Calling this method is potentially expensive for build contexts that correspond to RenderObjectWidgets (O(N) in the number of children).

Calling this method recursively is extremely expensive (O(N) in the number of descendants), and should be avoided if possible. Generally it is significantly cheaper to use an InheritedWidget and have the descendants pull data down than it is to use visit_child_elements recursively to push data down to them.

Source

pub fn debug_is_descendant_of(self, app: &App, target: AnyElement) -> bool

Dart’s _debugIsDescendantOf.

Source

pub fn mark_needs_build(self, app: &mut App)

Marks the element as dirty and adds it to the global list of widgets to rebuild in the next frame.

Since it is inefficient to build an element twice in one frame, applications and widgets should be structured so as to only mark widgets dirty during event handlers before the frame begins, not during the build itself.

Source

pub fn rebuild(self, app: &mut App, force: bool)

Cause the widget to update itself. In debug builds, also verify various invariants.

Called by the BuildOwner when BuildOwner::schedule_build_for has been called to mark this element dirty, by mount when the element is first built, and by update when the widget has changed.

The method will only rebuild if dirty is true. To rebuild irrespective of the dirty flag, set force to true. Forcing a rebuild is convenient when update is called, during which dirty is false.

Source

pub fn notification_tree(self, app: &App) -> Option<Rc<NotificationNode>>

The notification chain this element dispatches into.

Source

pub fn set_notification_tree( self, app: &mut App, tree: Option<Rc<NotificationNode>>, )

Sets the notification chain: a notifiable element chains a node for itself here.

Source

pub fn assign_owner(self, app: &mut App, owner: Handle<BuildOwner>)

RootElementMixin.assignOwner: set the owner of the element and its build scope.

The owner of an element is determined at mount, so this should only be called on a root element that is about to be mounted without a parent.

Trait Implementations§

Source§

impl Clone for AnyElement

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for AnyElement

Source§

impl Debug for AnyElement

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for AnyElement

Source§

impl Hash for AnyElement

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for AnyElement

Source§

fn eq(&self, other: &AnyElement) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Forget for AnyElement

§

impl Freeze for AnyElement
where NonZero<u32>: Freeze, &'static ElementVTable: Freeze,

§

impl Move for AnyElement

§

impl RefUnwindSafe for AnyElement

§

impl Send for AnyElement
where NonZero<u32>: Send, &'static ElementVTable: Send,

§

impl Sync for AnyElement
where NonZero<u32>: Sync,

§

impl Unpin for AnyElement
where NonZero<u32>: Unpin, &'static ElementVTable: Unpin,

§

impl UnsafeUnpin for AnyElement
where NonZeroU32Inner: UnsafeUnpin, &'static ElementVTable: UnsafeUnpin,

§

impl UnwindSafe for AnyElement
where NonZero<u32>: UnwindSafe, &'static ElementVTable: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyEq for T
where T: PartialEq + Hash + Debug + 'static,

Source§

fn eq_any(&self, other: &(dyn AnyEq + 'static)) -> bool

Dart’s operator ==. Must return false when other is a different concrete type, even if the two carry the same value.
Source§

fn hash_any(&self, state: &mut dyn Hasher)

Dart’s hashCode. Must mix in the concrete type so that two types carrying the same value do not collide.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SlotValue for T
where T: Clone + Eq + Hash + Debug + 'static,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,