resolveAs<T> method Null safety

T resolveAs<T>(
  1. T value,
  2. Set<MaterialState> states

Resolves the value for the given set of states if value is a MaterialStateProperty, otherwise returns the value itself.

This is useful for widgets that have parameters which can optionally be a MaterialStateProperty. For example, InkWell.mouseCursor can be a MouseCursor or a MaterialStateProperty<MouseCursor>.


static T resolveAs<T>(T value, Set<MaterialState> states) {
  if (value is MaterialStateProperty<T>) {
    final MaterialStateProperty<T> property = value;
    return property.resolve(states);
  return value;