Contents

constant_identifier_names

Contents

Prefer using lowerCamelCase for constant names.

This rule is available as of Dart 2.0.

Rule sets: recommended, flutter

This rule has a quick fix available.

Details

#

PREFER using lowerCamelCase for constant names.

In new code, use lowerCamelCase for constant variables, including enum values.

In existing code that uses ALL_CAPS_WITH_UNDERSCORES for constants, you may continue to use all caps to stay consistent.

BAD:

dart
const PI = 3.14;
const kDefaultTimeout = 1000;
final URL_SCHEME = RegExp('^([a-z]+):');

class Dice {
  static final NUMBER_GENERATOR = Random();
}

GOOD:

dart
const pi = 3.14;
const defaultTimeout = 1000;
final urlScheme = RegExp('^([a-z]+):');

class Dice {
  static final numberGenerator = Random();
}

Usage

#

To enable the constant_identifier_names rule, add constant_identifier_names under linter > rules in your analysis_options.yaml file:

analysis_options.yaml
yaml
linter:
  rules:
    - constant_identifier_names