fromAncestor<D, DAncestor> static method
Creates an InitialData that produces its initial value by calling initialValue with
a value of type DAncestor, obtained by from an ancestor state in the state tree.
class ParentData {
String value = '';
ParentData(this.value);
}
var parentState = StateKey('parent');
var childState = StateKey('child');
var builder = StateTreeBuilder(initialState: parentState);
builder.dataState<ParentData>(
parentState,
InitialData.value(ParentData('parent value')),
(_) {},
initialChild: childState);
builder.dataState<int>(
childState,
// Initialize the state data for the child state from the state data of
// the parent state
InitialData.fromAncestor((ParentData ancestorData) => ancestorData.length),
(_) {},
parent: parentState
);
Implementation
static InitialData<D> fromAncestor<D, DAncestor>(D Function(DAncestor ancData) initialValue) {
return InitialData._((ctx) => initialValue(ctx.dataValueOrThrow<DAncestor>()));
}