getViewByPath method
Implementation
Future<View> getViewByPath(String path) async {
final viewUrls = path.split('/');
final firstUrl = viewUrls.removeAt(0);
final firstViewUrlInfo = ViewUrlInfo.fromUrl(firstUrl);
final firstView = registeredViewsMap[firstViewUrlInfo.id];
if (firstView == null) {
throw Exception('view "${firstViewUrlInfo.id}" is not registered');
}
firstView.params = firstViewUrlInfo.params;
await firstView.init();
var parentView = firstView;
for (final viewUrl in viewUrls) {
if (viewUrl.isNotEmpty) {
final childViewUrlInfo = ViewUrlInfo.fromUrl(viewUrl);
final childView = registeredViewsMap[childViewUrlInfo.id];
if (childView == null) {
throw Exception('view "${childViewUrlInfo.id}" is not registered');
}
childView
..parent = parentView
..params = childViewUrlInfo.params;
await childView.init();
parentView = childView;
}
}
return parentView;
}