Merge pull request #1586 from collinjackson/dispatchOnScroll

Allow derived classes of Scrollable to listen for scroll events
This commit is contained in:
Collin Jackson 2015-10-12 17:13:01 -07:00
commit adb0d2e2df

View File

@ -166,8 +166,7 @@ abstract class ScrollableState<T extends Scrollable> extends State<T> {
setState(() { setState(() {
_scrollOffset = newScrollOffset; _scrollOffset = newScrollOffset;
}); });
if (config.onScroll != null) dispatchOnScroll();
config.onScroll(_scrollOffset);
} }
Future scrollTo(double newScrollOffset, { Duration duration, Curve curve: ease }) { Future scrollTo(double newScrollOffset, { Duration duration, Curve curve: ease }) {
@ -200,6 +199,12 @@ abstract class ScrollableState<T extends Scrollable> extends State<T> {
return _startToEndAnimation(); return _startToEndAnimation();
} }
// Derived classes can override this method and call super.dispatchOnScroll()
void dispatchOnScroll() {
if (config.onScroll != null)
config.onScroll(_scrollOffset);
}
double _scrollVelocity(ui.Offset velocity) { double _scrollVelocity(ui.Offset velocity) {
double scrollVelocity = config.scrollDirection == ScrollDirection.horizontal double scrollVelocity = config.scrollDirection == ScrollDirection.horizontal
? -velocity.dx ? -velocity.dx