of static method

AnimatedGridState of(
  1. BuildContext context

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.

If no AnimatedGrid surrounds the context given, then this function will assert in debug mode and throw an exception in release mode.

This method can be expensive (it walks the element tree).

This method does not create a dependency, and so will not cause rebuilding when the state changes.

See also:


static AnimatedGridState of(BuildContext context) {
  final AnimatedGridState? result = AnimatedGrid.maybeOf(context);
  assert(() {
    if (result == null) {
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary('AnimatedGrid.of() called with a context that does not contain an AnimatedGrid.'),
          'No AnimatedGrid ancestor could be found starting from the context that was passed to AnimatedGrid.of().',
          'This can happen when the context provided is from the same StatefulWidget that '
          'built the AnimatedGrid. Please see the AnimatedGrid documentation for examples '
          'of how to refer to an AnimatedGridState object:\n'
          '  https://api.flutter.dev/flutter/widgets/AnimatedGridState-class.html',
        context.describeElement('The context used was'),
    return true;
  return result!;