withFallback<T, R> static method

Future<R> withFallback<T, R>(
  1. dynamic provider,
  2. Future<R> action(
    1. T
    ),
  3. Future<R> fallback()
)

Execute action with fallback if capability not supported Best for: Graceful degradation

Implementation

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