ScrollBuilder.threshold constructor
ScrollBuilder.threshold({})
Implementation
factory ScrollBuilder.threshold({
Key? key,
required ScrollController controller,
required double threshold,
required Widget child,
Widget? before,
Duration duration = const Duration(milliseconds: 150),
bool showAfter = true,
}) {
double lastOffset = 0;
return ScrollBuilder(
controller: controller,
child: child,
key: key,
builder: (context, child) {
final isShown = showAfter ? controller.offset > threshold : controller.offset < threshold;
return AnimatedSwitcher(
duration: duration,
child: isShown ? child : (before ?? SizedBox(height: 0)),
);
},
shouldRebuild: () {
final newOffset = controller.offset;
final isSwitched =
(lastOffset < threshold && newOffset > threshold) || (lastOffset > threshold && newOffset < threshold);
lastOffset = newOffset;
return isSwitched;
});
}