Chemistry class Null safety

A singleton store of Atoms and Molecules. Atoms and Molecules can be added and used from anywhere in the program.

Example usage:

var chemistry = Chemistry();
chemistry.addAtom(Atom<int>(defaultValue: 0, key: 'someNumber'));
chemistry.addAtom(Atom<int>(defaultValue: 4, key: 'someOtherNumber'));
chemistry.addMolecule(Molecule<int>(
  atoms: [
    chemistry.getAtom<int>('someNumber'),
    chemistry.getAtom<int>('someOtherNumber')
  ],
  computer: (getAtom) => getAtom<int>('someNumber')!.state +
    getAtom<int>('someOtherNumber')!.state,
  key: 'someMolecule',
));

// Somewhere else in the program.
print(chemistry.getMolecule<int>('someMolecule')!.state);

Constructors

Chemistry()
Returns the instance of this store if it exists, otherwise creates it and returns the newly created instance.
factory

Properties

hashCode int
The hash code for this object.
read-onlyinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

addAtom<T>(Atom<T> atom) Atom<T>?
Adds an Atom to the store. atom is the Atom to be added to the store.
addMolecule<T>(Molecule<T> molecule) Molecule<T>?
Adds a Molecule to the store. molecule the Molecule to be added to the store.
dispose() → void
Calls the dispose() method and all atoms and molecules and then removes them. Think of this as a destructor that you have to call.
getAtom<T>(String key) Atom<T>?
Gets an Atom from the store. key the key of the Atom to get.
getMolecule<T>(String key) Molecule<T>?
Gets a Molecule from the store. key the key of the Molecule to get.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
removeAtom(String key) bool
Remove an Atom from the store. key the key of the Atom to remove.
removeMolecule(String key) bool
Remove a Molecule from the store. key the key of the Molecule to remove.
toString() String
A string representation of this object.
inherited

Operators

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