Component class abstract

Describes the configuration for an Element.

Components are the central class hierarchy in the jaspr framework and have the same structure and purpose as components do in Flutter. A component is an immutable description of part of a user interface. Components can be inflated into elements, which manage the underlying DOM.

Components themselves have no mutable state (all their fields must be final). If you wish to associate mutable state with a component, consider using a StatefulComponent, which creates a State object (via StatefulComponent.createState) whenever it is inflated into an element and incorporated into the tree.

A given component can be included in the tree zero or more times. In particular a given component can be placed in the tree multiple times. Each time a component is placed in the tree, it is inflated into an Element, which means a component that is incorporated into the tree multiple times will be inflated multiple times.

The key property controls how one component replaces another component in the tree. If the runtimeType and key properties of the two components are operator==, respectively, then the new component replaces the old component by updating the underlying element (i.e., by calling Element.update with the new component). Otherwise, the old element is removed from the tree, the new component is inflated into an element, and the new element is inserted into the tree.

See also:

  • StatefulComponent and State, for components that can build differently several times over their lifetime.
  • InheritedComponent, for components that introduce ambient state that can be read by descendant components.
  • StatelessComponent, for components that always build the same way given a particular configuration and ambient state.
Implementers
Annotations

Constructors

Component({Key? key})
Initializes key for subclasses.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one component replaces another component in the tree.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() Element
Inflates this configuration to a concrete instance.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

canUpdate(Component oldComponent, Component newComponent) bool
Whether the newComponent can be used to update an Element that currently has the oldComponent as its configuration.