Skip to content

Files

Latest commit

 

History

History
44 lines (36 loc) · 850 Bytes

use_decorated_box.md

File metadata and controls

44 lines (36 loc) · 850 Bytes

Pattern: Missing use of DecoratedBox

Issue: -

Description

DO use DecoratedBox when Container has only a Decoration.

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

Example of incorrect code:

Widget buildArea() {
 return Container(
  decoration: const BoxDecoration(
   color: Colors.blue,
   borderRadius: BorderRadius.all(
    Radius.circular(5),
   ),
  ),
  child: const Text('...'),
 );
}

Example of correct code:

Widget buildArea() {
 return const DecoratedBox(
  decoration: BoxDecoration(
   color: Colors.blue,
   borderRadius: BorderRadius.all(
    Radius.circular(5),
   ),
  ),
  child: Text('...'),
 );
}

Further Reading