getMolecule<T> method Null safety

Molecule<T>? getMolecule<T>(
  1. String key
)

Gets a Molecule from the store. key the key of the Molecule to get.

Returns the Molecule with the key Molecule from the store if it exist and if the Molecule is of the type Molecule

Implementation

Molecule<T>? getMolecule<T>(String key) {
  if (!_molecules.containsKey(key)) {
    return null;
  }

  var molecule = _molecules[key];

  if (molecule is! Molecule<T>) {
    return null;
  }

  return _molecules[key] as Molecule<T>;
}