use_ decorated_ box
Use 'DecoratedBox' rather than a 'Container' with only a 'Decoration'.
Description
#
The analyzer produces this diagnostic when a
Container
is created that
only sets the decoration.
Example
#
The following code produces this diagnostic because the only attribute of
the container that is set is the
decoration
:
import 'package:flutter/material.dart';
Widget buildArea() {
return Container(
decoration: const BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: const Text('...'),
);
}
Common fixes
#Replace the Container
with a DecoratedBox
:
import 'package:flutter/material.dart';
Widget buildArea() {
return DecoratedBox(
decoration: const BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: const Text('...'),
);
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.