scrollFirstWhere method

Future<bool> scrollFirstWhere(
  1. bool test(
    1. T item
    ), {
  2. bool animate = true,
  3. Duration duration = const Duration(milliseconds: 300),
  4. Curve curve = Curves.easeInOut,
  5. double alignment = 0.0,
  6. EdgeInsets padding = EdgeInsets.zero,
  7. BuildContext? sliverContext,
  8. bool isFixedHeight = false,
})

Scrolls to the first item matching test, using animation if animate is true.

This is a convenience method that calls either animateFirstWhere or jumpFirstWhere based on the animate parameter.

Example:

await cubit.scrollFirstWhere((item) => item.id == targetId, animate: true);
cubit.scrollFirstWhere((item) => item.isNew, animate: false);

Implementation

Future<bool> scrollFirstWhere(
  bool Function(T item) test, {
  bool animate = true,
  Duration duration = const Duration(milliseconds: 300),
  Curve curve = Curves.easeInOut,
  double alignment = 0.0,
  EdgeInsets padding = EdgeInsets.zero,
  BuildContext? sliverContext,
  bool isFixedHeight = false,
}) async {
  if (animate) {
    return animateFirstWhere(
      test,
      duration: duration,
      curve: curve,
      alignment: alignment,
      padding: padding,
      sliverContext: sliverContext,
      isFixedHeight: isFixedHeight,
    );
  } else {
    return jumpFirstWhere(
      test,
      alignment: alignment,
      padding: padding,
      sliverContext: sliverContext,
      isFixedHeight: isFixedHeight,
    );
  }
}