pathToName static method
Convert a list of path segments to a human-readable field name.
For example, the path [foo, bar, 1, baz]
becomes foo.bar[1].baz
.
Implementation
static String pathToName(List<String> path) {
if (path.isEmpty) {
return '';
}
final result = StringBuffer(path.first);
for (final part in path.skip(1)) {
final isArrayIndex = RegExp(r'^\d+$').hasMatch(part);
if (isArrayIndex) {
result.write('[$part]');
} else {
result.write('.$part');
}
}
return result.toString();
}