tryAs<T> function

T? tryAs<T>(
  1. dynamic object
)

Attempts to cast object to T, returning null on failure.

This is a workaround until as? is implemented: github.com/dart-lang/language/issues/399

Implementation

T? tryAs<T>(dynamic object) => (object is T) ? object : null;