Skip to main content

simplify_variable_pattern

Details about the 'simplify_variable_pattern' diagnostic produced by the Dart analyzer.

The {0} identification '{1}:' is redundant and can be removed.

Description

#

The analyzer produces this diagnostic when a variable pattern includes a redundant type member name.

Example

#

The following code produces this diagnostic because the variable pattern includes a redundant getter name:

dart
void f(Object o) {
  if (o case String(length: var length)) {
    print('string is $length characters long');
  }
}

Common fixes

#

Remove the redundant member name:

dart
void f(Object o) {
  if (o case String(:var length)) {
    print('string is $length characters long');
  }
}