acceptsInstance method

bool acceptsInstance(
  1. dynamic instance
)

Whether instance can be assigned to this type.

This is similar to the is operator, which can be replaced as such, using stringType as an example:

// Before
if (instance is String) {
  // Do some logic here
}

// After
if (stringType.acceptsInstance(instance)) {
  // Do some logic here
}

Note that unlike the is operator, this method does not type-promote. If you want to type-promote, consider using withInstance instead.

Implementation

bool acceptsInstance(dynamic instance) => instance is T;