handleScrollNotification method
bool
handleScrollNotification({
- required ScrollNotification notification,
- required ScrollController scrollController,
- required ValueNotifier<
bool> isCollapsedValueNotifier, - CollapsingStateCallback? onCollapseStateChanged,
Scrolling Notification listener
triggers haptic feedback and snaps the appbar to either collapse or expand depending on which state is closest to the current scrolling offset
Implementation
bool handleScrollNotification({
required ScrollNotification notification,
required ScrollController scrollController,
required ValueNotifier<bool> isCollapsedValueNotifier,
CollapsingStateCallback? onCollapseStateChanged,
}) {
/// The position at which we either collapse or expand
///
/// the threshold which if we exceed then we should expand
/// otherwise we should collapse the appbar
final double expandThresholdPosition =
(expandedBarHeight - collapsedBarHeight) / 1.75;
/// The current position of the scrolling
final double currentScrollingPosition = scrollController.offset;
/// sets the collapsed and expanded views as the user scrolls
//region Update isCollapsed value as user scrolls
_updateIsAppBarCollapsed(
isCollapsed: isCollapsedValueNotifier,
scrollController: scrollController,
expandThresholdPosition: expandThresholdPosition,
onCollapseStateChanged: onCollapseStateChanged,
);
//endregion
//region
if (notification is ScrollEndNotification) {
_snapAppBar(
currentScrollingPosition: currentScrollingPosition,
expandThresholdPosition: expandThresholdPosition,
scrollController: scrollController,
);
}
//endregion
return false;
}