addMolecule<T> method Null safety

Molecule<T>? addMolecule<T>(
  1. Molecule<T> molecule
)

Adds a Molecule to the store. molecule the Molecule to be added to the store.

Returns the Molecule added to the store if no Molecule with the same key exists, otherwise returns null.

Implementation

Molecule<T>? addMolecule<T>(Molecule<T> molecule) {
  if (_molecules.containsKey(molecule.key)) {
    return null;
  }

  return _molecules.putIfAbsent(molecule.key, () => molecule) as Molecule<T>;
}