of static method

ReorderableListState of(
  1. BuildContext context
)

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

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

If no ReorderableList surrounds the given context, 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).

See also:

Implementation

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