ValueCell<T>.computed constructor

ValueCell<T>.computed(
  1. T compute(), {
  2. dynamic key,
  3. bool changesOnly = false,
})

Create a cell which computes its value using the function compute.

Any cell referenced in compute by the call method is considered an argument cell. Any change in the value of an argument cell will result in the value of the returned cell being recomputed.

If changesOnly is true, the returned cell only notifies its observers if its value has actually changed.

The created cell is identified by key if non-null.

Example:

// `a` and `b` are both [ValueCell]'s
final sum = ValueCell.computed(() => a() + b());

The cell sum computes the sum of cells a and b. Whenever the value of either a or b changes, the value of sum is recomputed.

Implementation

factory ValueCell.computed(T Function() compute, {
  key,
  bool changesOnly = false
}) => DynamicComputeCell(
    compute,
    key: key,
    changesOnly: changesOnly
);