Skip to main content

Element

Trait Element 

Source
pub trait Element: Sized + 'static {
    const IS_RENDER_OBJECT_ELEMENT: bool = false;
    const IS_PARENT_DATA_ELEMENT: bool = false;
    const IS_INHERITED_ELEMENT: bool = false;
Show 36 methods // Required methods fn element_data(self: Handle<Self>, app: &App) -> &ElementData; fn element_data_mut(self: Handle<Self>, app: &mut App) -> &mut ElementData; // Provided methods fn as_element(self: Handle<Self>) -> AnyElement { ... } fn visit_children( self: Handle<Self>, app: &App, visitor: &mut dyn FnMut(AnyElement), ) { ... } fn debug_visit_onstage_children( self: Handle<Self>, app: &App, visitor: &mut dyn FnMut(AnyElement), ) { ... } fn render_object_attaching_child( self: Handle<Self>, app: &App, ) -> Option<AnyElement> { ... } fn mount( self: Handle<Self>, app: &mut App, parent: Option<AnyElement>, new_slot: Option<Slot>, ) { ... } fn update(self: Handle<Self>, app: &mut App, new_widget: WidgetRef) { ... } fn update_slot(self: Handle<Self>, app: &mut App, new_slot: Option<Slot>) { ... } fn attach_render_object( self: Handle<Self>, app: &mut App, new_slot: Option<Slot>, ) { ... } fn detach_render_object(self: Handle<Self>, app: &mut App) { ... } fn forget_child(self: Handle<Self>, app: &mut App, child: AnyElement) { ... } fn activate(self: Handle<Self>, app: &mut App) { ... } fn deactivate(self: Handle<Self>, app: &mut App) { ... } fn debug_deactivated(self: Handle<Self>, app: &mut App) { ... } fn unmount(self: Handle<Self>, app: &mut App) { ... } fn perform_rebuild(self: Handle<Self>, app: &mut App) { ... } fn did_change_dependencies(self: Handle<Self>, app: &mut App) { ... } fn update_inheritance(self: Handle<Self>, app: &mut App) { ... } fn attach_notification_tree(self: Handle<Self>, app: &mut App) { ... } fn build_scope(self: Handle<Self>, app: &App) -> Handle<BuildScope> { ... } fn mark_needs_build(self: Handle<Self>, app: &mut App) { ... } fn on_notification( self: Handle<Self>, app: &mut App, notification: &dyn Notification, ) -> bool { ... } fn debug_expects_render_object_for_slot( self: Handle<Self>, app: &App, slot: Option<&Slot>, ) -> bool { ... } fn render_object(self: Handle<Self>, app: &App) -> Option<AnyRenderObject> { ... } fn debug_doing_build(self: Handle<Self>, app: &App) -> bool { ... } fn insert_render_object_child( self: Handle<Self>, app: &mut App, child: AnyRenderObject, slot: Option<Slot>, ) { ... } fn move_render_object_child( self: Handle<Self>, app: &mut App, child: AnyRenderObject, old_slot: Option<Slot>, new_slot: Option<Slot>, ) { ... } fn remove_render_object_child( self: Handle<Self>, app: &mut App, child: AnyRenderObject, slot: Option<Slot>, ) { ... } fn update_parent_data( self: Handle<Self>, app: &mut App, parent_data_element: AnyElement, ) { ... } fn apply_parent_data( self: Handle<Self>, app: &mut App, render_object: AnyRenderObject, ) -> bool { ... } fn update_dependencies( self: Handle<Self>, app: &mut App, dependent: AnyElement, aspect: Option<Rc<dyn Any>>, ) { ... } fn remove_dependent( self: Handle<Self>, app: &mut App, dependent: AnyElement, ) { ... } fn state_handle_id( self: Handle<Self>, app: &App, ) -> Option<(TypeId, HandleId)> { ... } fn debug_fill_properties( self: Handle<Self>, app: &App, properties: &mut DiagnosticPropertiesBuilder, ) { ... } fn debug_describe_children( self: Handle<Self>, app: &App, ) -> Vec<Rc<dyn DiagnosticsNode>> { ... }
}
Expand description

An instantiation of a Widget at a particular location in the tree.

Widgets describe how to configure a subtree but the same widget can be used to configure multiple subtrees simultaneously because widgets are immutable. An Element represents the use of a widget to configure a specific location in the tree. Over time, the widget associated with a given element can change, for example, if the parent widget rebuilds and creates a new widget for this location.

The overridable methods default to Dart’s base bodies; an override that must run the base as well calls it through ElementBase (ElementBase::mount(self, ..)), where Dart calls super.

Provided Associated Constants§

Source

const IS_RENDER_OBJECT_ELEMENT: bool = false

Dart’s this is RenderObjectElement.

Source

const IS_PARENT_DATA_ELEMENT: bool = false

Dart’s this is ParentDataElement.

Source

const IS_INHERITED_ELEMENT: bool = false

Dart’s this is InheritedElement.

Required Methods§

Source

fn element_data(self: Handle<Self>, app: &App) -> &ElementData

Dart’s base-class fields, held under the field element (element_accessors!).

Source

fn element_data_mut(self: Handle<Self>, app: &mut App) -> &mut ElementData

Provided Methods§

Source

fn as_element(self: Handle<Self>) -> AnyElement

The type-erased handle to this element.

Source

fn visit_children( self: Handle<Self>, app: &App, visitor: &mut dyn FnMut(AnyElement), )

Calls the argument for each child. Must be overridden by subclasses that support having children.

There is no guaranteed order in which the children will be visited, though it should be consistent over time.

Source

fn debug_visit_onstage_children( self: Handle<Self>, app: &App, visitor: &mut dyn FnMut(AnyElement), )

Calls the argument for each child considered onstage.

Classes like Offstage and Overlay override this method to hide their children.

Being onstage affects the element’s discoverability during testing when you use flutter_test’s Finder. Offstage elements are ignored by finders by default.

Most widgets are not visible when offstage, but that is not always the case: an element that is offstage here may still paint.

Source

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

Returns the child of this Element that will insert a RenderObject into an ancestor of this Element to construct the render tree.

Returns None if this Element doesn’t have any children who need to attach a RenderObject to an ancestor of this Element. A RenderObjectElement will therefore return None because its children insert their RenderObjects into the RenderObjectElement itself and not into an ancestor of the RenderObjectElement.

Source

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

Add this element to the tree in the given slot of the given parent.

The framework calls this function when a newly created element is added to the tree for the first time. Use this method to initialize state that depends on having a parent. State that is independent of the parent can more easily be initialized in the constructor.

Source

fn update(self: Handle<Self>, app: &mut App, new_widget: WidgetRef)

Change the widget used to configure this element.

The framework calls this function when the parent wishes to use a different widget to configure this element. The new widget is guaranteed to have the same runtimeType as the old widget.

Source

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

Called by AnyElement::update_slot_for_child when the slot for a child has changed.

Source

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

Add AnyElement::render_object to the render tree at the location specified by new_slot.

The default implementation of this function calls attach_render_object recursively on each child. The RenderObjectElement::attach_render_object override does the actual work of adding AnyElement::render_object to the render tree.

Source

fn detach_render_object(self: Handle<Self>, app: &mut App)

Remove AnyElement::render_object from the render tree.

The default implementation of this function calls detach_render_object recursively on each child. The RenderObjectElement::detach_render_object override does the actual work of removing AnyElement::render_object from the render tree.

Source

fn forget_child(self: Handle<Self>, app: &mut App, child: AnyElement)

Remove the given child from the element’s child list, in preparation for the child being reused elsewhere in the element tree.

Source

fn activate(self: Handle<Self>, app: &mut App)

Transition from the “inactive” to the “active” lifecycle state.

Source

fn deactivate(self: Handle<Self>, app: &mut App)

Transition from the “active” to the “inactive” lifecycle state.

Source

fn debug_deactivated(self: Handle<Self>, app: &mut App)

Called, in debug mode, after children have been deactivated.

Source

fn unmount(self: Handle<Self>, app: &mut App)

Transition from the “inactive” to the “defunct” lifecycle state.

Source

fn perform_rebuild(self: Handle<Self>, app: &mut App)

Cause the widget to update itself.

Called by AnyElement::rebuild after the appropriate checks have been made.

Source

fn did_change_dependencies(self: Handle<Self>, app: &mut App)

Called when a dependency of this element changes.

Source

fn update_inheritance(self: Handle<Self>, app: &mut App)

Dart’s _updateInheritance: inherit the parent’s inherited-element map.

Source

fn attach_notification_tree(self: Handle<Self>, app: &mut App)

Called in mount and activate to register this element in the notification tree.

This method is only exposed so that notifiable elements can be implemented (Dart’s NotifiableElementMixin): an element that wishes to respond to notifications overrides it to insert a node for itself, and on_notification to handle them.

See also:

  • NotificationListener, a widget that allows listening to notifications.
Source

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

The BuildScope whose dirty list this element is in.

The BuildOwner builds the dirty elements of one scope per build_scope call; an element that wants its own (a LayoutBuilder, whose subtree is built during layout) overrides this.

Source

fn mark_needs_build(self: Handle<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

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

Called when a notification of the appropriate type arrives at this location in the tree (Dart’s NotifiableElementMixin.onNotification).

Return true to cancel the notification bubbling. Return false to allow the notification to continue to be dispatched to further ancestors. Only elements that override attach_notification_tree are asked.

Source

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

Whether the child in the provided slot (or one of its descendants) must insert a RenderObject into its ancestor RenderObjectElement by calling RenderObjectElement::insert_render_object_child on it.

Source

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

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

Source

fn debug_doing_build(self: Handle<Self>, app: &App) -> bool

Whether this element is in the middle of building.

Source

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

RenderObjectElement.insertRenderObjectChild.

Source

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

RenderObjectElement.moveRenderObjectChild.

Source

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

RenderObjectElement.removeRenderObjectChild.

Source

fn update_parent_data( self: Handle<Self>, app: &mut App, parent_data_element: AnyElement, )

RenderObjectElement._updateParentData: apply a parent-data widget to this element’s render object.

Source

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

ParentDataWidget.applyParentData through the element that holds the widget.

Source

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

InheritedElement.updateDependencies.

Source

fn remove_dependent(self: Handle<Self>, app: &mut App, dependent: AnyElement)

InheritedElement.removeDependent.

Source

fn state_handle_id(self: Handle<Self>, app: &App) -> Option<(TypeId, HandleId)>

Dart’s this is StatefulElement && state is T: the state’s type and arena id.

Source

fn debug_fill_properties( self: Handle<Self>, app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties as an element class overrides it: the properties it adds after Element’s, and RenderObjectElement’s for a render object element, which the framework adds first since a trait default cannot call super.

Source

fn debug_describe_children( self: Handle<Self>, app: &App, ) -> Vec<Rc<dyn DiagnosticsNode>>

Dart’s debugDescribeChildren: the children a dump shows under this element, by default every child visit_children visits.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Element for InheritedElement

Source§

impl Element for LayoutBuilderElement

Source§

impl Element for LeafRenderObjectElement

Source§

impl Element for MultiChildComponentElement

Source§

impl Element for MultiChildRenderObjectElement

Source§

impl Element for ParentDataElement

Source§

impl Element for RawViewElement

Source§

impl Element for RootElement

Source§

impl Element for SingleChildRenderObjectElement

Source§

impl Element for SingleChildViewportElement

Source§

impl Element for StatefulElement

Source§

impl Element for StatelessElement

Source§

impl Element for ViewportElement

Source§

impl<T: ?Sized + NotificationTarget> Element for NotificationElement<T>

Source§

impl<W: InheritedModel> Element for InheritedModelElement<W>

Source§

impl<W: InheritedNotifier> Element for InheritedNotifierElement<W>

Source§

impl<W: SliverMultiBoxAdaptorWidget> Element for SliverMultiBoxAdaptorElement<W>

Source§

impl<W: SlottedMultiChildRenderObjectWidget> Element for SlottedRenderObjectElement<W>