use-full-hex-values-for-flutter-colors

Same as use_full_hex_values_for_flutter_colors in Dart lints

Group
Style
Path
lint/style/use-full-hex-values-for-flutter-colors
Default
On (recommended)
Origin
Dart lints
Domain
flutter
Rule
490 of 512
recommendedflutter

Require an eight-digit hexadecimal integer for the canonical Flutter Color default constructor.

Invalid

example.dartdart
// Bad: Color constructed with fewer than 8 hex digits.
import 'package:flutter/material.dart';
import 'dart:ui' as ui;

final c0 = Color(0xFFFFFF);

final c1 = Color(0x00FF00);

final c2 = Color(0xABC);

final c3 = Color(0Xff0000);

final c4 = Color(0xF);

final c5 = Color(0xFF00FF);

final c6 = ui.Color(16777215);
final c7 = ui.Color(0x1FFFFFFFF);
final c8 = ui.Color(0xFF_FF_FF);

final c9 = const Color(0xFFFFFF);
Use the full 8-digit hexadecimal value (0xAARRGGBB) for a Color.
4
5final c0 = Color(0xFFFFFF);
Use the full 8-digit hexadecimal value (0xAARRGGBB) for a Color.
6
7final c1 = Color(0x00FF00);
Use the full 8-digit hexadecimal value (0xAARRGGBB) for a Color.
8
9final c2 = Color(0xABC);
Use the full 8-digit hexadecimal value (0xAARRGGBB) for a Color.
10
11final c3 = Color(0Xff0000);
Use the full 8-digit hexadecimal value (0xAARRGGBB) for a Color.
12
13final c4 = Color(0xF);
Use the full 8-digit hexadecimal value (0xAARRGGBB) for a Color.
14
15final c5 = Color(0xFF00FF);
Use the full 8-digit hexadecimal value (0xAARRGGBB) for a Color.
16
17final c6 = ui.Color(16777215);
Use the full 8-digit hexadecimal value (0xAARRGGBB) for a Color.
17final c6 = ui.Color(16777215);
18final c7 = ui.Color(0x1FFFFFFFF);
Use the full 8-digit hexadecimal value (0xAARRGGBB) for a Color.
18final c7 = ui.Color(0x1FFFFFFFF);
19final c8 = ui.Color(0xFF_FF_FF);
Use the full 8-digit hexadecimal value (0xAARRGGBB) for a Color.
20
21final c9 = const Color(0xFFFFFF);

Valid

example.dartdart
// Good: full 8-digit hex colors, or not a bare Color() call.
import 'package:flutter/material.dart';

final c0 = Color(0xFFFFFFFF);

final c1 = Color(0x00FF00FF);

final c2 = Color(0xFF123456);

final c3 = Colors.red;

final c4 = Color.fromARGB(255, 0, 0, 0);

final c5 = Color(0xFFAABBCC);

final c6 = const Color.fromARGB(255, 0, 0, 1);

final c7 = const Color(0xFFAABBCC);

Configure use-full-hex-values-for-flutter-colors

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "use-full-hex-values-for-flutter-colors": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/use-full-hex-values-for-flutter-colors: <reason>
  • use-function-type-syntax-for-parametersuse_function_type_syntax_for_parametersrecommended

    Flags an old-style function-typed parameter written with inline parameter syntax.

  • use-if-null-to-convert-nulls-to-boolsuse_if_null_to_convert_nulls_to_boolsrecommended

    Prefers ?? to comparing a nullable bool against a boolean literal.

  • use-late-for-private-fields-and-variablesuse_late_for_private_fields_and_variables

    Flags a private nullable field or top-level variable that is only ever assigned non-null values and read through !, so it could be late with a non-nullable type.

  • use-named-constantsuse_named_constantsrecommended

    Prefers a class's predefined static constant to constructing an equal constant.

  • use-raw-stringsuse_raw_strings

    Flags string literals whose only escapes are \\ and \$, which a raw string would express without any backslash.

  • use-setters-to-change-propertiesuse_setters_to_change_properties

    Flags one-parameter void methods that only assign that parameter to a field.

  • use-spacer-as-expanded-childuse_spacer_as_expanded_childrecommendedflutter

    Flags an Expanded wrapping an empty SizedBox or Container that should be a Spacer.

  • use-string-in-part-of-directivesuse_string_in_part_of_directivesrecommended

    Flags a part of directive that names its library instead of using a string URI.