目錄
目錄

Use ColoredBox.

This rule is available as of Dart 2.17.0.

Details

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 rule, add use_colored_box under linter > rules in your analysis_options.yaml file:

linter:
  rules:
    - use_colored_box