getDeepValue<T> method

T? getDeepValue<T>(
  1. String keyPath
)

Reads a value of T type from persistent storage for the given keyPath when keyPath is a Json path separated by ':' like 'appColors:primaryColor' when our Json file is:

{
    "appColors": {
        "primaryColor": "#2e7d32"
    }
}

You can also use getDeepValue

Implementation

T? getDeepValue<T>(String keyPath) {
  dynamic _value;

  keyPath.split(":").forEach((element) {
    if (_value == null)
      _value = appConfig[element];
    else
      _value = _value[element];
  });

  if (_value != null) {
    if (T == Color) _value = _hexStringToColor(_value);

    return _value as T;
  }

  return null;
}