getByPathString<T> method

T getByPathString<T>(
  1. String path, {
  2. dynamic def,
})

the path is a String path fot access to a node. for example "posts/news/1/title"

Implementation

T getByPathString<T>(String path, {dynamic def}) {
  if (path.endsWith('/')) {
    path = path.substring(0, path.length - 1);
  }

  if (path.startsWith('/')) {
    path = path.substring(1, path.length);
  }

  List<dynamic> arr = <dynamic>[];
  for (var element in Uri(path: path).pathSegments) {
    arr.add(int.tryParse(element) ?? element);
  }

  return getByPath<T>(arr, def: def);
}