ElementaryWidget<I extends IWidgetModel> class abstract

A widget that uses state of WidgetModel properties to build a part of the user interface described by this widget.

For inheritors of this widget is common to be parameterized by the interface expanded from IWidgetModel that provides all special information which needed for this widget for correctly describe the subtree.

Only one thing should be implemented in inheritors of this widget is a build method. Build method in this case is pure function which gets the WidgetModel as argument and based on this WidgetModel returns the Widget. There isn't additional interactions with anything external, everything needed for describe should be provided by WidgetModel.

{@tool snippet}

The following widget shows a default example of Flutter app, which created with a new Flutter project.

class ExampleWidget extends ElementaryWidget<IExampleWidgetModel> {
  const ExampleWidget({
    Key? key,
    WidgetModelFactory wmFactory = exampleWidgetModelFactory,
  }) : super(wmFactory, key: key);

  @override
  Widget build(IExampleWidgetModel wm) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Test'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('You have pushed the button this many times:'),
            ValueListenableBuilder<int>(
              valueListenable: wm.pressCountPublisher,
              builder: (_, value, __) {
                return Text(value.toString());
              },
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: wm.increment,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

{@end-tool}

wmFactory

An instance of the WidgetModelFactory must be provided to the widget constructor as wmFactory property. This is required to create the WidgetModel instance for this widget. You can use additional factories for different purpose. For example create a special one that returns a mock WidgetModel for the tests.

The part of Elementary Lifecycle

This widget is a starting and updating configuration for the WidgetModel. More details about using it while life cycle see in the methods docs of the WidgetModel.

Internal details

This widget doesn't have its own RenderObject, and just describes a part of the user interface using other widgets. It is a common approach for the widgets those inflate to ComponentElement.

See also: StatelessWidget, StatefulWidget, InheritedWidget.

Inheritance

Constructors

ElementaryWidget(WidgetModelFactory<WidgetModel<ElementaryWidget<IWidgetModel>, ElementaryModel>> wmFactory, {Key? key})
Creates an instance of ElementaryWidget.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
wmFactory WidgetModelFactory<WidgetModel<ElementaryWidget<IWidgetModel>, ElementaryModel>>
The factory function used to create a WidgetModel.
final

Methods

build(I wm) Widget
Describes the part of the user interface represented by this widget, based on the state of the WidgetModel passed to the wm argument.
createElement() → Elementary
Creates a Elementary to manage this widget's location in the tree.
override
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.
inherited
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.
inherited

Operators

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