getOptional<T> method

T? getOptional<T>(
  1. String key
)

Reads a value. Allows the database value to be null. Throws if the key is missing from the schema or the type mismatches.

Implementation

T? getOptional<T>(String key) {
  _validateAccess<T>(key);

  final value = _raw[key];
  if (value != null && value is! T) {
    throw StateError(
      'DB Type Mismatch: Expected $T? for "$key", got ${value.runtimeType}.',
    );
  }
  return value as T?;
}