tryGet method

  1. @override
Asset? tryGet([
  1. Supplier<Exception>? orElseThrow
])
override

Attempts to retrieve the asset safely.

  • If the asset exists, it is returned.
  • If the asset does not exist, returns null instead of throwing, unless orElseThrow is provided, in which case the supplied exception will be thrown.

Example

final asset = resource.tryGet();
if (asset != null) {
  print("Asset loaded successfully");
} else {
  print("Asset not found");
}

Implementation

@override
Asset? tryGet([Supplier<Exception>? orElseThrow]) {
  if(_asset != null) {
    return _asset!;
  } else if(orElseThrow != null) {
    throw orElseThrow();
  } else {
    return null;
  }
}