update method
Change the widget used to configure this element.
The framework calls this function when the parent wishes to use a different widget to configure this element. The new widget is guaranteed to have the same runtimeType as the old widget.
This function is called only during the "active" lifecycle state.
Implementation
@override
void update(JoltProvider newWidget) {
final oldStore = _store;
final oldCreate = widget.create;
final oldValue = widget.value;
super.update(newWidget);
assert(widget == newWidget);
final newCreate = newWidget.create;
final newValue = newWidget.value;
final valueChanged = !identical(oldValue, newValue);
final switchingToCreate = oldCreate == null && newCreate != null;
final switchingToValue = oldCreate != null && newCreate == null;
if (switchingToCreate) {
T? newStore;
if (newWidget.create != null && _didInitValue) {
_scope!.run(() {
newStore = newWidget.create!.call(this) as T?;
});
}
final storeChanged = !identical(oldStore, newStore);
if (storeChanged && _didInitValue) {
_store = newStore;
if (_store != null && _store is JoltState) {
_scope!.run(() {
(_store as JoltState).onMount(this);
});
}
}
}
if ((valueChanged || switchingToValue) && newCreate == null) {
if (switchingToValue && oldStore != null) {
if (oldStore is JoltState) {
_scope!.run(() {
(oldStore as JoltState).onUnmount(this);
});
}
if (oldStore is Disposable) {
(oldStore as Disposable).dispose();
}
}
_store = newValue;
if (switchingToValue) {
_didInitValue = true;
}
}
rebuild(force: true);
}