of static method

AnimatedGridState? 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 AnimatedGrid item widgets that insert or remove items in response to user input.

AnimatedListState animatedList = AnimatedList.of(context);

Implementation

static AnimatedGridState? of(BuildContext context, {bool nullOk = false}) {
  final AnimatedGridState? result =
      context.findAncestorStateOfType<AnimatedGridState>();
  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 AnimatedGridState object: '
      '  https://api.flutter.dev/flutter/widgets/AnimatedGridState-class.html \n'
      'The context used was:\n'
      '  $context');
}