animateFirstWhere method

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

Animates to the first item matching the given test function.

The duration defaults to 300ms. The curve defaults to Curves.easeInOut. The alignment determines where the item should be positioned in the viewport (0.0 = top/left, 0.5 = center, 1.0 = bottom/right).

Returns a Future that completes with true if a matching item was found and scrolled to, or false if no match was found or no controller is attached.

Example:

await cubit.animateFirstWhere((item) => item.id == targetId);
await cubit.animateFirstWhere(
  (item) => item.name.contains('search'),
  duration: Duration(milliseconds: 500),
);

Implementation

Future<bool> animateFirstWhere(
  bool Function(T item) test, {
  Duration duration = const Duration(milliseconds: 300),
  Curve curve = Curves.easeInOut,
  double alignment = 0.0,
  EdgeInsets padding = EdgeInsets.zero,
  BuildContext? sliverContext,
  bool isFixedHeight = false,
}) async {
  final items = currentItems;
  final index = items.indexWhere(test);

  if (index == -1) {
    _logger.d('animateFirstWhere: no matching item found');
    return false;
  }

  return animateToIndex(
    index,
    duration: duration,
    curve: curve,
    alignment: alignment,
    padding: padding,
    sliverContext: sliverContext,
    isFixedHeight: isFixedHeight,
  );
}