use_colored_box

Group: style

Maturity: stable

Dart SDK: >= 2.17.0 • (Linter v1.19.0)

Since info is static, may be stale

View all Lint Rules

Using the Linter

DO use ColoredBox when Container has only a Color.

A Container is a heavier Widget than a ColoredBox, and as bonus, ColoredBox has a const constructor.

BAD:

Widget buildArea() {
  return Container(
    color: Colors.blue,
    child: const Text('hello'),
  );
}

GOOD:

Widget buildArea() {
  return const ColoredBox(
    color: Colors.blue,
    child: Text('hello'),
  );
}

Usage

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

linter:
  rules:
    - use_colored_box