of method Null safety

SliverReorderableListState of(
  1. BuildContext context
)

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

This method is typically used by SliverReorderableList item widgets to start or cancel an item drag operation.

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

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

See also:

Implementation

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