Atom<T> class Null safety

An atom is a single piece of state. It can be used independently or combined with Chemistry. This is a generic class which allows it to be used very dynamically.

Example usage:

var myAtom = Atom<String>(defaultValue: 'Welcome', key: 'myAtom');
myAtom.stateStream.listen((state) => print(state));

Constructors

Atom({required T defaultValue, required String key})
Constructor that returns a new atom. defaultValue the default value of this Atom, used to avoid setting null as the default value. key a globally unique key that identifies this Atom.

Properties

hashCode int
The hash code for this object.
read-onlyinherited
key String
A globally unique key. Usually the same as the name of this Atom.
latefinal
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited
state → T
Get the state of this Atom.
read-only
stateStream Stream<T>
A broadcast stream that can be listened to. Whenever the state of this Atom changes a new event will be emited on this stream providing the listener with the new state.
read-only

Methods

dispose() → void
The dispose method should always be called before this atom is destroyed. It will close _controller. Think of this as a destructor that you have to manually call.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
setState(T newState) → void
Set the state of this atom. This will emit an event on the stateStream stream. newState the state to be set as this Atom's state.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited