ConditionalOnProperty constructor

const ConditionalOnProperty({
  1. String? prefix,
  2. List<String> names = const [],
  3. String? havingValue,
  4. bool matchIfMissing = false,
})

Marks a class or method as conditional based on the presence and value of configuration properties.

This annotation is used to include or exclude a class based on one or more environment or system properties. It is commonly used in auto-configuration or module activation scenarios.

Matching Rules

  • You can specify multiple names via names.
  • If havingValue is specified, the property must match that value.
  • If havingValue is omitted, the property must not be equal to 'false'.
  • If the property is missing and matchIfMissing is true, it will match.

Example

@ConditionalOnProperty(
  prefix: 'server',
  names: ['ssl.enabled', 'ssl.enabled2'],
  havingValue: 'true',
)
class SslServerConfig {}

This activates SslServerConfig only if server.ssl.enabled=true.

Implementation

const ConditionalOnProperty({
  this.prefix,
  this.names = const [],
  this.havingValue,
  this.matchIfMissing = false,
});