Skip to content

Commit 81bc54b

Browse files
authored
Enable use_colored_box lint (#117370)
1 parent 46bb853 commit 81bc54b

File tree

72 files changed

+198
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+198
-194
lines changed

analysis_options.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ linter:
221221
- unrelated_type_equality_checks
222222
- unsafe_html
223223
- use_build_context_synchronously
224-
# - use_colored_box # not yet tested
224+
- use_colored_box
225225
# - use_decorated_box # leads to bugs: DecoratedBox and Container are not equivalent (Container inserts extra padding)
226226
- use_enums
227227
- use_full_hex_values_for_flutter_colors

dev/benchmarks/complex_layout/lib/src/app.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ class ItemGalleryBox extends StatelessWidget {
524524
child: Column(
525525
children: <Widget>[
526526
Expanded(
527-
child: Container(
527+
child: ColoredBox(
528528
color: Theme.of(context).primaryColor,
529529
child: Center(
530530
child: Text(tabName, style: Theme.of(context).textTheme.headlineSmall!.copyWith(color: Colors.white)),

dev/benchmarks/macrobenchmarks/lib/src/backdrop_filter.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class _BackdropFilterPageState extends State<BackdropFilterPage> with TickerProv
9191
child: addBlur(grid(txt, 17, 5), _blurGroup),
9292
),
9393
const SizedBox(height: 20),
94-
Container(
94+
ColoredBox(
9595
color: Colors.white,
9696
child:Row(
9797
mainAxisAlignment: MainAxisAlignment.center,

dev/benchmarks/macrobenchmarks/lib/src/post_backdrop_filter.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ class _PostBackdropFilterPageState extends State<PostBackdropFilterPage> with Ti
7474
),
7575
getConditionalBackdrop(),
7676
RepaintBoundary(
77-
child: Container(
77+
child: ColoredBox(
7878
color: Colors.white,
79-
child:Row(
79+
child: Row(
8080
mainAxisAlignment: MainAxisAlignment.center,
8181
children: <Widget>[
8282
const Text('Include BackdropFilter:'),

dev/integration_tests/android_views/lib/wm_integrations.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
8888
Widget _statusWidget() {
8989
assert(_lastTestStatus != _LastTestStatus.pending);
9090
final String? message = _lastTestStatus == _LastTestStatus.success ? 'Success' : lastError;
91-
return Container(
91+
return ColoredBox(
9292
color: _lastTestStatus == _LastTestStatus.success ? Colors.green : Colors.red,
9393
child: Text(
9494
message!,

dev/integration_tests/flutter_gallery/lib/demo/animation/home.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ class _AnimationDemoHomeState extends State<AnimationDemoHome> {
520520

521521
final List<Widget> headings = <Widget>[];
522522
for (int index = 0; index < allSections.length; index++) {
523-
headings.add(Container(
523+
headings.add(ColoredBox(
524524
color: _kAppBackgroundColor,
525525
child: ClipRect(
526526
child: _AllSectionsView(

dev/integration_tests/flutter_gallery/lib/demo/cupertino/cupertino_navigation_demo.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class Tab1RowItem extends StatelessWidget {
214214
),
215215
));
216216
},
217-
child: Container(
217+
child: ColoredBox(
218218
color: CupertinoDynamicColor.resolve(CupertinoColors.systemBackground, context),
219219
child: SafeArea(
220220
top: false,

dev/integration_tests/flutter_gallery/lib/demo/fortnightly/fortnightly.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ over water meant for the whole central valley of California? The story will shoc
9595
return SingleChildScrollView(
9696
child: SafeArea(
9797
top: false,
98-
child: Container(
98+
child: ColoredBox(
9999
color: Theme.of(context).colorScheme.surface,
100100
child: Column(
101101
children: <Widget>[

dev/integration_tests/flutter_gallery/lib/demo/material/backdrop_demo.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderSt
358358
);
359359
}).toList();
360360

361-
return Container(
361+
return ColoredBox(
362362
key: _backdropKey,
363363
color: theme.primaryColor,
364364
child: Stack(

dev/integration_tests/flutter_gallery/lib/demo/material/leave_behind_demo.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,15 @@ class _LeaveBehindListItem extends StatelessWidget {
243243
}
244244
return false;
245245
},
246-
background: Container(
246+
background: ColoredBox(
247247
color: theme.primaryColor,
248248
child: const Center(
249249
child: ListTile(
250250
leading: Icon(Icons.delete, color: Colors.white, size: 36.0),
251251
),
252252
),
253253
),
254-
secondaryBackground: Container(
254+
secondaryBackground: ColoredBox(
255255
color: theme.primaryColor,
256256
child: const Center(
257257
child: ListTile(

dev/integration_tests/hybrid_android_views/lib/nested_view_event_page.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class NestedViewEventBodyState extends State<NestedViewEventBody> {
122122
Widget _statusWidget() {
123123
assert(_lastTestStatus != _LastTestStatus.pending);
124124
final String message = _lastTestStatus == _LastTestStatus.success ? 'Success' : lastError!;
125-
return Container(
125+
return ColoredBox(
126126
color: _lastTestStatus == _LastTestStatus.success ? Colors.green : Colors.red,
127127
child: Text(
128128
message,

dev/manual_tests/lib/star_border.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class _MyHomePageState extends State<MyHomePage> {
6666
),
6767
body: Column(
6868
children: <Widget>[
69-
Container(color: Colors.grey.shade200, child: Options(_model)),
69+
ColoredBox(color: Colors.grey.shade200, child: Options(_model)),
7070
Expanded(
7171
child: Row(
7272
mainAxisAlignment: MainAxisAlignment.spaceEvenly,

dev/manual_tests/lib/text.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
508508

509509
@override
510510
Widget build(BuildContext context) {
511-
return Container(
511+
return ColoredBox(
512512
color: Colors.black,
513513
child: Column(
514514
children: <Widget>[
@@ -577,7 +577,7 @@ class _UnderlinesState extends State<Underlines> {
577577
@override
578578
Widget build(BuildContext context) {
579579
final Size size = MediaQuery.of(context).size;
580-
return Container(
580+
return ColoredBox(
581581
color: Colors.black,
582582
child: Column(
583583
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -680,7 +680,7 @@ class _FallbackState extends State<Fallback> {
680680
@override
681681
Widget build(BuildContext context) {
682682
final Size size = MediaQuery.of(context).size;
683-
return Container(
683+
return ColoredBox(
684684
color: Colors.black,
685685
child: Column(
686686
children: <Widget>[
@@ -754,7 +754,7 @@ class Bidi extends StatefulWidget {
754754
class _BidiState extends State<Bidi> {
755755
@override
756756
Widget build(BuildContext context) {
757-
return Container(
757+
return ColoredBox(
758758
color: Colors.black,
759759
child: ListView(
760760
padding: const EdgeInsets.symmetric(vertical: 40.0, horizontal: 20.0),
@@ -862,7 +862,7 @@ class _ZalgoState extends State<Zalgo> with SingleTickerProviderStateMixin {
862862

863863
@override
864864
Widget build(BuildContext context) {
865-
return Container(
865+
return ColoredBox(
866866
color: Colors.black,
867867
child: Column(
868868
children: <Widget>[
@@ -988,7 +988,7 @@ class _PaintingState extends State<Painting> with SingleTickerProviderStateMixin
988988
@override
989989
Widget build(BuildContext context) {
990990
final Size size = MediaQuery.of(context).size;
991-
return Container(
991+
return ColoredBox(
992992
color: Colors.black,
993993
child: Column(
994994
crossAxisAlignment: CrossAxisAlignment.stretch,

examples/api/lib/cupertino/context_menu/cupertino_context_menu.0.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ class ContextMenuExample extends StatelessWidget {
6767
child: const Text('Delete'),
6868
),
6969
],
70-
child: Container(
70+
child: const ColoredBox(
7171
color: CupertinoColors.systemYellow,
72-
child: const FlutterLogo(size: 500.0),
72+
child: FlutterLogo(size: 500.0),
7373
),
7474
),
7575
),

examples/api/lib/material/divider/divider.0.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ class DividerExample extends StatelessWidget {
3030
return Center(
3131
child: Column(
3232
children: <Widget>[
33-
Expanded(
34-
child: Container(
33+
const Expanded(
34+
child: ColoredBox(
3535
color: Colors.amber,
36-
child: const Center(
36+
child: Center(
3737
child: Text('Above'),
3838
),
3939
),
@@ -59,7 +59,7 @@ class DividerExample extends StatelessWidget {
5959
),
6060
),
6161
Expanded(
62-
child: Container(
62+
child: ColoredBox(
6363
color: Theme.of(context).colorScheme.primary,
6464
child: const Center(
6565
child: Text('Below'),

examples/api/lib/material/reorderable_list/reorderable_list_view.build_default_drag_handles.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class _ReorderableExampleState extends State<ReorderableExample> {
4242
buildDefaultDragHandles: false,
4343
children: <Widget>[
4444
for (int index = 0; index < _items.length; index++)
45-
Container(
45+
ColoredBox(
4646
key: Key('$index'),
4747
color: _items[index].isOdd ? oddItemColor : evenItemColor,
4848
child: Row(

examples/api/lib/painting/star_border/star_border.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class _StarBorderExampleState extends State<StarBorderExample> {
6666
),
6767
child: ListView(
6868
children: <Widget>[
69-
Container(
69+
ColoredBox(
7070
color: Colors.grey.shade200,
7171
child: Options(_model),
7272
),

examples/api/lib/widgets/animated_size/animated_size.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
4949
Widget build(BuildContext context) {
5050
return GestureDetector(
5151
onTap: () => _updateSize(),
52-
child: Container(
52+
child: ColoredBox(
5353
color: Colors.amberAccent,
5454
child: AnimatedSize(
5555
curve: Curves.easeIn,

examples/api/lib/widgets/animated_switcher/animated_switcher.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
3434

3535
@override
3636
Widget build(BuildContext context) {
37-
return Container(
37+
return ColoredBox(
3838
color: Colors.white,
3939
child: Column(
4040
mainAxisAlignment: MainAxisAlignment.center,

examples/api/lib/widgets/basic/listener.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
6969
onPointerDown: _incrementDown,
7070
onPointerMove: _updateLocation,
7171
onPointerUp: _incrementUp,
72-
child: Container(
72+
child: ColoredBox(
7373
color: Colors.lightBlueAccent,
7474
child: Column(
7575
mainAxisAlignment: MainAxisAlignment.center,

examples/api/lib/widgets/basic/mouse_region.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
6767
onEnter: _incrementEnter,
6868
onHover: _updateLocation,
6969
onExit: _incrementExit,
70-
child: Container(
70+
child: ColoredBox(
7171
color: Colors.lightBlueAccent,
7272
child: Column(
7373
mainAxisAlignment: MainAxisAlignment.center,

examples/api/lib/widgets/focus_manager/focus_node.unfocus.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
3636
@override
3737
Widget build(BuildContext context) {
3838
return Material(
39-
child: Container(
39+
child: ColoredBox(
4040
color: Colors.white,
4141
child: Column(
4242
mainAxisAlignment: MainAxisAlignment.center,

examples/api/lib/widgets/focus_traversal/focus_traversal_group.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class MyStatelessWidget extends StatelessWidget {
125125

126126
@override
127127
Widget build(BuildContext context) {
128-
return Container(
128+
return ColoredBox(
129129
color: Colors.white,
130130
child: FocusTraversalGroup(
131131
policy: OrderedTraversalPolicy(),

examples/api/lib/widgets/implicit_animations/animated_fractionally_sized_box.0.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
4747
child: SizedBox(
4848
width: 200,
4949
height: 200,
50-
child: Container(
50+
child: ColoredBox(
5151
color: Colors.red,
5252
child: AnimatedFractionallySizedBox(
5353
widthFactor: selected ? 0.25 : 0.75,
5454
heightFactor: selected ? 0.75 : 0.25,
5555
alignment: selected ? Alignment.topLeft : Alignment.bottomRight,
5656
duration: const Duration(seconds: 1),
5757
curve: Curves.fastOutSlowIn,
58-
child: Container(
58+
child: const ColoredBox(
5959
color: Colors.blue,
60-
child: const FlutterLogo(size: 75),
60+
child: FlutterLogo(size: 75),
6161
),
6262
),
6363
),

examples/api/lib/widgets/implicit_animations/animated_positioned.0.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
5656
selected = !selected;
5757
});
5858
},
59-
child: Container(
59+
child: const ColoredBox(
6060
color: Colors.blue,
61-
child: const Center(child: Text('Tap me')),
61+
child: Center(child: Text('Tap me')),
6262
),
6363
),
6464
),

examples/api/lib/widgets/transitions/align_transition.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget>
5757

5858
@override
5959
Widget build(BuildContext context) {
60-
return Container(
60+
return ColoredBox(
6161
color: Colors.white,
6262
child: AlignTransition(
6363
alignment: _animation,

examples/api/lib/widgets/transitions/decorated_box_transition.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget>
7070

7171
@override
7272
Widget build(BuildContext context) {
73-
return Container(
73+
return ColoredBox(
7474
color: Colors.white,
7575
child: Center(
7676
child: DecoratedBoxTransition(

examples/api/lib/widgets/transitions/fade_transition.0.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget>
5050

5151
@override
5252
Widget build(BuildContext context) {
53-
return Container(
53+
return ColoredBox(
5454
color: Colors.white,
5555
child: FadeTransition(
5656
opacity: _animation,

examples/api/test/material/divider/divider.0_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ void main() {
1818

1919
expect(find.byType(Divider), findsOneWidget);
2020

21-
// Divider is positioned horizintally.
22-
final Offset container = tester.getBottomLeft(find.byType(Container).first);
21+
// Divider is positioned horizontally.
22+
final Offset container = tester.getBottomLeft(find.byType(ColoredBox).first);
2323
expect(container.dy, tester.getTopLeft(find.byType(Divider)).dy);
2424

2525
final Offset subheader = tester.getTopLeft(find.text('Subheader'));

packages/flutter/lib/src/animation/animation.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ abstract class Animation<T> extends Listenable implements ValueListenable<T> {
8181
/// final double opacity = (value / 1000).clamp(0, 1);
8282
/// return Opacity(opacity: opacity, child: child);
8383
/// },
84-
/// child: Container(
84+
/// child: const ColoredBox(
8585
/// color: Colors.red,
86-
/// child: const Text('Hello, Animation'),
86+
/// child: Text('Hello, Animation'),
8787
/// ),
8888
/// );
8989
/// }
@@ -100,9 +100,9 @@ abstract class Animation<T> extends Listenable implements ValueListenable<T> {
100100
/// opacity: Animation<double>.fromValueListenable(_scrollPosition, transformer: (double value) {
101101
/// return (value / 1000).clamp(0, 1);
102102
/// }),
103-
/// child: Container(
103+
/// child: const ColoredBox(
104104
/// color: Colors.red,
105-
/// child: const Text('Hello, Animation'),
105+
/// child: Text('Hello, Animation'),
106106
/// ),
107107
/// );
108108
/// }

packages/flutter/lib/src/cupertino/dialog.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class CupertinoAlertDialog extends StatelessWidget {
289289
),
290290
];
291291

292-
return Container(
292+
return ColoredBox(
293293
color: CupertinoDynamicColor.resolve(_kDialogColor, context),
294294
child: Column(
295295
mainAxisSize: MainAxisSize.min,
@@ -555,7 +555,7 @@ class CupertinoActionSheet extends StatelessWidget {
555555
content.add(Flexible(child: titleSection));
556556
}
557557

558-
return Container(
558+
return ColoredBox(
559559
color: CupertinoDynamicColor.resolve(_kActionSheetBackgroundColor, context),
560560
child: Column(
561561
mainAxisSize: MainAxisSize.min,

0 commit comments

Comments
 (0)