Listenables class

Annotation to create a class to put together Listenable.

Define the class as follows and use build_runner for code generation.

Listenableをまとめるためのクラスを作成するアノテーション。

下記のようにクラスを定義してbuild_runnerでコードジェネレーションを行ないます。

@listenables
class ListenableValue with _$ListenableValue, ChangeNotifier {
  factory ListenableValue({
    required TextEditingController controller,
    ValueNotifier<String> value,
  }) = _ListenableValue;
}

You can create an object with initial values based on the generated class.

生成されたクラスを元に初期値を入れオブジェクトを作成できます。

final listenable = ListenableValue(
  controller: TextEditingController(text: "initial value"),
  value: ValueNotifier("initial")
);

Within the generated object, all classes inheriting from the defined Listenable are automatically monitored, and all are notified to the grouping object (here ListenableValue).

By using addListener, it is not necessary to add, remove, or dispose of multiple Listenable objects, and the code can be simplified.

生成されたオブジェクト内では定義されたListenableを継承したクラスはすべて自動で監視され、すべてグループ化したオブジェクト(ここではListenableValue)に通知されます。

これをaddListenerすることで複数のListenableオブジェクトをaddListener、removeListener、disposeする必要がなくコードが簡略化可能になります。

Available Extensions

Constructors

Listenables()
Annotation to create a class to put together Listenable.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

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