of<T extends Service> static method
Finds the Service from the closest instance of this class that encloses the given context.
If no instance of this class encloses the given context, will cause an assert in debug mode, and throw an exception in release mode.
Implementation
static T of<T extends Service>(BuildContext context) {
final T? result = maybeOf<T>(context);
if (result != null) {
return result;
}
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary(
"Service.of<T>() called with a context that does not contain a ServiceProvider<Service<T>>.",
),
context.describeElement("The context used was"),
]);
}