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 SliverAnimatedGrid item widgets that insert or remove items in response to user input.
If no SliverAnimatedGrid 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).
See also:
- maybeOf, a similar function that will return null if no SliverAnimatedGrid ancestor is found.
Implementation
static SliverAnimatedGridState of(BuildContext context) {
final SliverAnimatedGridState? result = context.findAncestorStateOfType<SliverAnimatedGridState>();
assert(() {
if (result == null) {
throw FlutterError(
'SliverAnimatedGrid.of() called with a context that does not contain a SliverAnimatedGrid.\n'
'No SliverAnimatedGridState ancestor could be found starting from the '
'context that was passed to SliverAnimatedGridState.of(). This can '
'happen when the context provided is from the same StatefulWidget that '
'built the AnimatedGrid. Please see the SliverAnimatedGrid documentation '
'for examples of how to refer to an AnimatedGridState object: '
'https://api.flutter-io.cn/flutter/widgets/SliverAnimatedGridState-class.html\n'
'The context used was:\n'
' $context',
);
}
return true;
}());
return result!;
}