valueListenableAtom<T> function
AtomWithParent<T, Atom<ValueListenable<T> > >
valueListenableAtom<T>(
- ValueListenable<
T> create(- AtomContext<
ValueListenable< getT> >
- AtomContext<
Create an Atom that listens to a ValueListenable.
Implementation
AtomWithParent<T, Atom<ValueListenable<T>>> valueListenableAtom<T>(
ValueListenable<T> Function(AtomContext<ValueListenable<T>> get) create,
) =>
atomWithParent(atom(create), (get, parent) {
final listenable = get(parent);
void onChange() => get.setSelf(listenable.value);
listenable.addListener(onChange);
get.onDispose(() => listenable.removeListener(onChange));
return listenable.value;
});