scroll method
moves the scroller by the specified pixels in the specified direction
Implementation
void scroll(double? pixels, {required bool animate}) {
try {
// check if pixels is null
pixels ??= 0;
// scroll up/left
if (pixels < 0) {
// already at the start of the list
if (controller.offset == 0) return;
// calculate pixels
pixels = controller.offset - pixels.abs();
if (pixels < 0) pixels = 0;
if (animate) {
controller.animateTo(pixels,
duration: const Duration(milliseconds: 300),
curve: Curves.easeOut);
}
else {
controller.jumpTo(pixels);
}
return;
}
// scroll down/right
if (pixels > 0) {
// already at the end of the list
if (controller.position.maxScrollExtent == controller.offset) return;
// calculate pixels
pixels = controller.offset + pixels;
if (pixels > controller.position.maxScrollExtent) pixels = controller.position.maxScrollExtent;
if (animate) {
controller.animateTo(pixels,
duration: const Duration(milliseconds: 300),
curve: Curves.easeOut);
}
else {
controller.jumpTo(pixels);
}
return;
}
}
catch (e) {
Log().exception(e, caller: 'scroller.View');
}
}