getOrFail method

  1. @override
Future<Map<String, dynamic>> getOrFail(
  1. String key, {
  2. Exception onFail()?,
})

Implementation

@override
Future<Map<String, dynamic>> getOrFail(String key,
    {Exception Function()? onFail}) async {
  final value = await get(key);
  if (value == null) {
    if (onFail case Function()) {
      throw onFail!();
    }

    throw Exception('Key $key not found');
  }

  return value;
}