onGetValue method

  1. @override
Future<T> onGetValue(
  1. String k
)
override

Asynchronously retrieves the value associated with the given key from the nested storage map.

Supports dot-separated keys for nested access (e.g., 'parent.child'). Traverses the map hierarchy, casting the final value to T. Throws an Exception if the key path is invalid or not found. Integrates with getValue for error handling and subject emission. No side effects beyond reading from storage.

Implementation

@override
Future<T> onGetValue(String k) async {
  List<String> parts = k.split('.');
  Map<String, dynamic> current = storage;
  for (int i = 0; i < parts.length; i++) {
    String part = parts[i];

    if (i == parts.length - 1) {
      if (current.containsKey(part)) {
        return current[part] as T;
      } else {
        throw Exception("Key not found: $k");
      }
    } else {
      if (current[part] is Map<String, dynamic>) {
        current = current[part] as Map<String, dynamic>;
      } else {
        throw Exception("Key not found: $k");
      }
    }
  }

  throw Exception("Key not found: $k");
}