scrollToTarget method

Future<void> scrollToTarget(
  1. String id, {
  2. bool smooth = true,
})

Scrolls to the target section with the given id.

If smooth is true (the default), the scrolling will be animated smoothly, as defined by Bootstrap's smooth scroll behavior. If false, it jumps to the section immediately.

Implementation

Future<void> scrollToTarget(String id, {bool smooth = true}) async {
  final key = _targets[id];
  if (key == null || key.currentContext == null) return;

  final context = key.currentContext!;
  if (smooth) {
    await Scrollable.ensureVisible(
      context,
      duration: const Duration(milliseconds: 300),
      curve: Curves.easeInOut,
    );
  } else {
    Scrollable.ensureVisible(
      context,
      duration: Duration.zero,
    );
  }
}