scrollTo method
滚动到锚点位置,如果 url 包含了 # 符号,则会自动解析字符串,否则直接当做 name 访问
Implementation
void scrollTo(String? url) {
if (url != null) {
BuildContext? context;
// 如果 url 存在 # 锚点符号,则尝试解析 url 地址获取 ElLink 的 context 对象
if (url.contains('#')) {
final key = Uri.decodeComponent(url).split('#').last;
context = getContext(_getKey(key));
}
// 若是单纯的字符串,则当作 name 直接访问
else {
context = getContext(_getKey(url));
}
if (context != null) {
Scrollable.ensureVisible(context);
}
}
}