scroll method

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

Implementation

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