mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 11:08:03 +08:00
26
lib/utils/extension/scroll_controller_ext.dart
Normal file
26
lib/utils/extension/scroll_controller_ext.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
extension ScrollControllerExt on ScrollController {
|
||||
void animToTop() => animTo(0);
|
||||
|
||||
void animTo(
|
||||
double offset, {
|
||||
Duration duration = const Duration(milliseconds: 500),
|
||||
}) {
|
||||
if (!hasClients) return;
|
||||
if ((offset - this.offset).abs() >= position.viewportDimension * 7) {
|
||||
jumpTo(offset);
|
||||
} else {
|
||||
animateTo(
|
||||
offset,
|
||||
duration: duration,
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void jumpToTop() {
|
||||
if (!hasClients) return;
|
||||
jumpTo(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user