getInt method

Future<int?> getInt(
  1. String key, {
  2. int? defaultValue,
})

Returns the stored int, or defaultValue if the key does not exist.

Implementation

Future<int?> getInt(String key, {int? defaultValue}) async {
  try {
    final raw = await _storage.read(key: key);
    if (raw == null) return defaultValue;
    return int.tryParse(raw) ?? defaultValue;
  } catch (e, st) {
    throw StorageException(
      message: 'Failed to get int',
      key: key,
      cause: e,
      stackTrace: st,
    );
  }
}