use_ decorated_ box
Details about the 'use_decorated_box' diagnostic produced by the Dart analyzer.
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('...'),
);
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.