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
:
dart
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
:
dart
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.7.3. Page last updated on 2025-05-08. View source or report an issue.