WidgetModel<W extends ElementaryWidget<IWidgetModel> , M extends ElementaryModel> class
abstract
The basic implementation of the entity responsible for all presentation logic, providing properties and data for the widget, and keep relations with the business logic. Business logic represented in the form of ElementaryModel.
WidgetModel is a working horse of the Elementary library. It unites the trio of 'widget - widget model - model'. So the inheritors of WidgetModel parameterized by an inheritor of the ElementaryWidget and an inheritor of the ElementaryModel. This mean that this WidgetModel subclass encapsulate all required logic for the concrete ElementaryWidget subclass that mentioned as parameter and only for it. Also this WidgetModel subclass uses exactly the mentioned ElementaryModel subclass as an available contract of business logic.
It is common for inheritors to implement the expanded from IWidgetModel interface that describes special contract for the relevant ElementaryWidget subclass. Moreover using the contract is preferable way because this interface explicitly shows available properties and methods for declarative part (for ElementaryWidget).
Approach to update
It is a rare case when ElementaryWidget completely rebuild. The most common case is a partial rebuild of UI parts. In order to get this, using publishers can be helpful. Declare any publishers which you prefer and update their values in suitable conditions. In the declarative part just use these publishers for describe parts of the UI, which depends on them. Here is a far from complete list of options for use as publishers: Stream, ChangeNotifier, StateNotifier, EntityStateNotifier.
The part of Elementary Lifecycle
Base class contains all internal mechanisms and process that need to guarantee the conceived behavior for the Elementary library.
initWidgetModel is called only once for lifecycle of the WidgetModel in the really beginning before the first build. It can be used for initiate a starting state of the WidgetModel.
didUpdateWidget called whenever widget instance in the tree has been updated. Common case where rebuild comes from the top. This method is a good place for update state of the WidgetModel based on the new configuration of widget. When this method is called is just a signal for decide what exactly should be updated or rebuilt. The fact of update doesn't mean that build method of the widget will be called. Set new values to publishers for rebuild concrete parts of the UI.
didChangeDependencies called whenever dependencies which WidgetModel subscribed with BuildContext change. When this method is called is just a signal for decide what exactly should be updated or rebuilt. The fact of the call doesn't mean that build method of the widget will be called. Set new values to publishers for rebuild concrete parts of the UI.
deactivate called when the WidgetModel with Elementary
removed from
the tree.
activate called when WidgetModel with Elementary
are reinserted into
the tree after having been removed via deactivate.
dispose called when WidgetModel is going to be permanently destroyed.
reassemble called whenever the application is reassembled during debugging, for example during the hot reload.
onErrorHandle called when the ElementaryModel handle error with the ElementaryModel.handleError method. Can be useful for general handling errors such as showing snack-bars.
- Implemented types
- Mixed in types
- Implementers
Constructors
- WidgetModel(M _model)
- Creates an instance of the WidgetModel.
Properties
- context → BuildContext
-
The location in the tree where this widget builds.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isMounted → bool
-
Whether WidgetModel and
Elementary
are currently mounted in the tree.no setter - model → M
-
Instance of ElementaryModel for this WidgetModel.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- widget → W
-
Widget that uses this WidgetModel for building part of the user interface.
no setter
Methods
-
activate(
) → void -
Called when this WidgetModel and
Elementary
are reinserted into the tree after having been removed via deactivate. -
deactivate(
) → void -
Called when this WidgetModel and
Elementary
are removed from the tree. -
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
didChangeDependencies(
) → void - Called when a dependency (by Build Context) of this Widget Model changes.
-
didUpdateWidget(
W oldWidget) → void - Called whenever the widget configuration is changed.
-
dispose(
) → void -
Called when
Elementary
with this WidgetModel is removed from the tree permanently. Should be used for preparation to be garbage collected. -
initWidgetModel(
) → void - Called while the first build for initialization of this WidgetModel.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onErrorHandle(
Object error) → void - Called whenever ElementaryModel.handleError is called.
-
reassemble(
) → void - Called whenever the application is reassembled during debugging, for example during hot reload. Most cases therefore do not need to do anything in the reassemble method.
-
setupTestElement(
BuildContext? testElement) → void - Method for associate another element to this WidgetModel. MUST be used only for testing purposes.
-
setupTestWidget(
W? testWidget) → void - Method for associate another instance of the widget to this WidgetModel. MUST be used only for testing purposes.
-
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
-
toStringShort(
) → String -
A brief description of this object, usually just the runtimeType and the
hashCode.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited