of static method

SliverAnimatedListState of(
  1. BuildContext context
)

The SliverAnimatedListState 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.

If no SliverAnimatedList 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:

Implementation

static SliverAnimatedListState of(BuildContext context) {
  final SliverAnimatedListState? result = SliverAnimatedList.maybeOf(context);
  assert(() {
    if (result == null) {
      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://api.flutter-io.cn/flutter/widgets/SliverAnimatedListState-class.html\n'
            'The context used was:\n'
            '  $context',
      );
    }
    return true;
  }());
  return result!;
}