of static method
- BuildContext context
The state from the closest instance of this class that encloses the given context.
This method is typically used by AnimatedReorderable item widgets that insert or remove items in response to user input.
If no AnimatedReorderable 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:
- maybeOf, a similar function that will return null if no AnimatedReorderable ancestor is found.
Implementation
static AnimatedReorderableState of(BuildContext context) {
final AnimatedReorderableState? result =
AnimatedReorderable.maybeOf(context);
assert(() {
if (result == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary(
'AnimatedReorderable.of() called with a context that does not contain an AnimatedReorderable.'),
ErrorDescription(
'No AnimatedReorderable ancestor could be found starting from the context that was passed to AnimatedReorderable.of().',
),
ErrorHint(
'This can happen when the context provided is from the same StatefulWidget that '
'built the AnimatedReorderable. Please see the AnimatedReorderable documentation for examples '
'of how to refer to an AnimatedReorderableState object:\n'
' https://pub.dev/packages/animated_reorderable',
),
context.describeElement('The context used was'),
]);
}
return true;
}());
return result!;
}