scroll method

dynamic scroll(
  1. Event event,
  2. ScrollController? sc
)

Implementation

scroll(Event event, ScrollController? sc) async {
  try {
    if (event.parameters!.containsKey("direction") &&
        event.parameters!.containsKey("pixels")) {
      String? direction = event.parameters!["direction"];
      double distance = double.parse(event.parameters!["pixels"]!);
      if (direction != null) {
        if (direction == 'left' || direction == 'right') {
          double offset = sc!.offset;
          double moveToPosition =
              offset + (direction == 'left' ? -distance : distance);
          sc.animateTo(moveToPosition,
              duration: const Duration(milliseconds: 300),
              curve: Curves.easeOut);
        } else if (direction == 'up' || direction == 'down') {
          double offset = sc!.offset;
          double moveToPosition =
              offset + (direction == 'up' ? -distance : distance);
          sc.animateTo(moveToPosition,
              duration: const Duration(milliseconds: 300),
              curve: Curves.easeOut);
        }
      }
    }
  } catch (e) {
    Log().error('onScroll Error: ');
    Log().exception(e, caller: 'table.View');
  }
}