PlayRoomNotifier class
NOTE: 以下の点を把握した上で状態管理を実装すること.
- 独自に定義した Class を Value としているため、notifyListeners() の明示的な呼び出しが必要である点.
- State は現状 mutable である点.
- immutable に扱おうと思うと、"value = State(a, b, c, d...)" という代入による更新が必要であり面倒.
- copy_with_extension や freezed で copyWith を生やせば対応可能なので、必要に迫られたら導入する.
- provider の文脈での参照にやや難がある点.
- PlayRoomNotifier に関して Widget が参照したいのは、value(PlayRoomState) と PlayRoomNotifier インスタンス の 2 つである.
ValueNotifierProvider だと value(PlayRoomState) を provide することになるため、PlayRoomNotifier インスタンスを provide できない.
そのため、現状は ChangeNotifierProvider で PlayRoomNotifier インスタンスを provide し、.value
を必要に応じて参照することにしている. - flutter_state_notifier を導入することで対応可能(notifyListeners の話も含め)なので、必要に迫られたら導入する.
- PlayRoomNotifier に関して Widget が参照したいのは、value(PlayRoomState) と PlayRoomNotifier インスタンス の 2 つである.
- Inheritance
- Object
- ChangeNotifier
- ValueNotifier<
PlayRoomState> - PlayRoomNotifier
Constructors
-
PlayRoomNotifier(I18n _i18n, Dice _dice, Store _store, Doc<
PlayRoomEntity> _playRoom)
Properties
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- hasListeners → bool
-
Whether any listeners are currently registered. [...]
@protected, read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
- value ↔ PlayRoomState
-
The current value stored in this notifier. [...]
read / write, inherited
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes. [...]
inherited
-
chooseDirection(
Direction direction) → Future< void> - 分岐路において、進行方向を選択して進む
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener and removeListener will throw after the object is
disposed). [...]
@mustCallSuper, inherited
-
init(
) → Future< void> - 初期化する LifeRoad や User の取得、LifeStage の初期値追加 TODO: コンストラクタ内でやればいい。そして、UI 側は listen するように改修する。んで、非同期処理の完了について無知でいられる。
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
notifyListeners(
) → void -
Call all the registered listeners. [...]
@protected, @visibleForTesting, inherited
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes. [...]
inherited
-
rollDice(
) → Future< void> - Dice を振って進む
-
toString(
) → String -
Returns a string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator. [...]
inherited