scrollTo method

  1. @override
void scrollTo(
  1. String? id,
  2. String? value, {
  3. bool animate = false,
})
override

scroll to specified item by id and value

Implementation

@override
void scrollTo(String? id, String? value, {bool animate = false}) {

  if (id == null) return;

  // get the view
  MenuViewState? view = findListenerOfExactType(MenuViewState);

  // scroll to top
  if (id.trim().toLowerCase() == 'top' && isNullOrEmpty(value)) {
    view?.scrollTo(0, animate: false);
    return;
  }

  // scroll to bottom
  if (id.trim().toLowerCase() == 'bottom' && isNullOrEmpty(value)) {
    view?.scrollTo(double.maxFinite, animate: false);
    return;
  }

  // scroll to specific pixel position
  if (isNumeric(id) && isNullOrEmpty(value)) {
    view?.scrollTo(toDouble(id), animate: false);
  }


  // find the first item containing a child with the specified
  // id and matching value
  for (var item in items) {
    var child = item.descendants?.toList().firstWhereOrNull((child) => child.id == id && child.value == (value ?? child.value));
    if (child != null) {
      view?.scrollToContext(child.context, animate: animate);
      break;
    }
  }
}