of method

AnimatedListState of (BuildContext context, { bool nullOk: false })

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

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

AnimatedListState animatedList = AnimatedList.of(context);

Implementation

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