withCapability<T, R> static method

Future<R?> withCapability<T, R>(
  1. dynamic provider,
  2. Future<R> action(
    1. T
    )
)

Execute action safely with capability check Returns null if capability not supported

Implementation

static Future<R?> withCapability<T, R>(
  dynamic provider,
  Future<R> Function(T) action,
) async {
  if (provider is T) {
    return await action(provider);
  }
  return null;
}