Nested class

A component that simplify the writing of deeply nested component trees.

It relies on the new kind of component SingleChildComponent, which has two concrete implementations:

They are both respectively a SingleChildComponent variant of StatelessComponent and StatefulComponent.

The difference between a component and its single-child variant is that they have a custom build method that takes an extra parameter.

As such, a StatelessComponent would be:

class MyComponent extends StatelessComponent {
  MyComponent({Key key, this.child}): super(key: key);

  final Component child;

  @override
  Iterable<Component> build(BuildContext context) sync* {
    yield SomethingComponent(child: child);
  }
}

Whereas a SingleChildStatelessComponent would be:

class MyComponent extends SingleChildStatelessComponent {
  MyComponent({Key key, Component child}): super(key: key, child: child);

  @override
  Iterable<Component> buildWithChild(BuildContext context, Component child) sync* {
    yield SomethingComponent(child: child);
  }
}

This allows our new MyComponent to be used both with:

MyComponent(
  child: AnotherComponent(),
)

and to be placed inside children of Nested like so:

Nested(
  children: [
    MyComponent(),
    ...
  ],
  child: AnotherComponent(),
)
Implemented types
Implementers

Constructors

Nested({Key? key, required List<SingleChildComponent> children, Component? child})
Allows configuring key, children and child

Properties

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

Methods

build(BuildContext context) Iterable<Component>
Describes the part of the user interface represented by this component.
createElement() → _NestedElement
Creates a StatelessElement to manage this component's location in the tree.
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