of method

SliverAnimatedListState of (
  1. BuildContext context,
  2. {bool nullOk: false}
)

The state from the closest instance of this class that encloses the given context.

This method is typically used by SliverAnimatedList item widgets that insert or remove items in response to user input.

SliverAnimatedListState animatedList = SliverAnimatedList.of(context);

Implementation

static SliverAnimatedListState of(BuildContext context, {bool nullOk = false}) {
  assert(context != null);
  assert(nullOk != null);
  final SliverAnimatedListState result = context.findAncestorStateOfType<SliverAnimatedListState>();
  if (nullOk || result != null)
    return result;
  throw FlutterError(
      'SliverAnimatedList.of() called with a context that does not contain a SliverAnimatedList.\n'
      'No SliverAnimatedListState ancestor could be found starting from the '
      'context that was passed to SliverAnimatedListState.of(). This can '
      'happen when the context provided is from the same StatefulWidget that '
      'built the AnimatedList. Please see the SliverAnimatedList documentation '
      'for examples of how to refer to an AnimatedListState object: '
      'https://docs.flutter.io/flutter/widgets/SliverAnimatedListState-class.html \n'
      'The context used was:\n'
      '  $context');
}