Atom<T> constructor

Atom<T>({
  1. required String key,
  2. required T defaultValue,
  3. List<AtomEffect<T>>? effects,
})

Creates an Atom, which represents a piece of writeable state

  • Define a unique key in order to identify the relative atom
  • Use defaultValue in order to set the initial value of the Atom
  • Use effects in order to add custom actions to Atom
    1. T value represents onItemSet and it's called every time Atom value change
    2. ValueNotifier<T> represents setItemData useful to change value of current Atom

It's possibile to create an array of effects to give different actions to Atom:

final fooAtom = Atom(
  key: 'foo_atom_key',
  defaultValue: initialValue,
  effects: [
    (onItemSet, setItemData) {
      // First Effect
    },
    (onItemSet, setItemData) {
      // Second Effect
    },
  ],
);

See also:

Implementation

Atom({
  required String key,
  required this.defaultValue,
  this.effects,
}) : super(key: key);