Widget class abstract

Describes the configuration for an Element.

Widgets are the central class hierarchy in the Flutter framework. A widget is an immutable description of part of a user interface. Widgets can be inflated into elements, which manage the underlying render tree.

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

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

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

See also:

  • StatefulWidget and State, for widgets that can build differently several times over their lifetime.
  • InheritedWidget, for widgets that introduce ambient state that can be read by descendant widgets.
  • StatelessWidget, for widgets that always build the same way given a particular configuration and ambient state.
Inheritance
Implementers
Annotations

Constructors

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

Properties

hashCode int
The hash code for this object.
no setteroverride
key Key?
Controls how one widget replaces another widget 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.
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
override

Operators

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

Static Methods

canUpdate(Widget oldWidget, Widget newWidget) bool
Whether the newWidget can be used to update an Element that currently has the oldWidget as its configuration.