validateProps method

  1. @Deprecated('4.0.0')
  2. @mustCallSuper
  3. @override
void validateProps(
  1. Map appliedProps
)
override

Throws a PropError if appliedProps are invalid.

Deprecated. Will be removed in the 4.0.0 release. Use propTypes instead.

Bad

mixin MyProps on UiProps {
  List listThatMustHaveAnEvenNumberOfItems;
}

class MyComponent extends UiComponent2<MyProps> {
  void validateProps(Map appliedProps) {
    super.validateProps(appliedProps);

    var tProps = typedPropsFactory(appliedProps);
    if (tProps.items.length.isOdd) {
      throw PropError.value(tProps.items, 'items', 'must have an even number of items, because reasons');
    }
  }
}

Good

mixin MyProps on UiProps {
  List listThatMustHaveAnEvenNumberOfItems;
}

class MyComponent extends UiComponent2<MyProps> {
  @override
  get propTypes => {
    keyForProp((p) => p.listThatMustHaveAnEvenNumberOfItems): (props, info) {
      if (props.listThatMustHaveAnEvenNumberOfItems?.length.isOdd) {
        return PropError.value(
            tProps.listThatMustHaveAnEvenNumberOfItems,
            'listThatMustHaveAnEvenNumberOfItems',
            'must have an even number of items, because reasons');
      }
      return null;
    },
  };
}

Implementation

@Deprecated('4.0.0')
@mustCallSuper
@override
void validateProps(Map appliedProps) {
  throw UnsupportedError('[validateProps] is not supported in UiComponent2, use [propTypes] instead.');
}