propTypes property

Map<String, PropValidator<Never>> propTypes

Allows usage of PropValidator functions to check the validity of a prop within the props passed to it.

The second argument (info) contains metadata about the prop specified by the key. propName, componentName, location and propFullName are available.

When an invalid value is provided for a prop, a warning will be shown in the JavaScript console.

For performance reasons, propTypes is only checked in development mode.

Simple Example:

@override
get propTypes => {
  'name': (Map props, info) {
    if (props['name'].length > 20) {
      return ArgumentError('(${props['name']}) is too long. 'name' has a max length of 20 characters.');
    }
  },
};

Example of 2 props being dependent:

@override
get propTypes => {
  'someProp': (Map props, info) {
    if (props[info.propName] == true && props['anotherProp'] == null) {
      return ArgumentError('If (${props[info.propName]}) is true. You must have a value for "anotherProp".');
    }
  },
  'anotherProp': (Map props, info) {
    if (props[info.propName] != null && props['someProp'] != true) {
      return ArgumentError('You must set "someProp" to true to use $[info.propName].');
    }
  },
};

See: reactjs.org/docs/typechecking-with-proptypes.html#proptypes

Implementation

Map<String, PropValidator<Never>> get propTypes => {};