Skip to content

Commit fa3777b

Browse files
authored
Enable sized_box_shrink_expand lint (#117371)
* Enable lint * note about discarded_futures * note about use_decorated_box * update note on require_trailing_commas
1 parent 8289ea6 commit fa3777b

19 files changed

+52
-156
lines changed

analysis_options.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ linter:
9898
- deprecated_consistency
9999
# - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib)
100100
- directives_ordering
101-
# - discarded_futures # not yet tested
101+
# - discarded_futures # too many false positives, similar to unawaited_futures
102102
# - do_not_use_environment # there are appropriate times to use the environment, especially in our tests and build logic
103103
- empty_catches
104104
- empty_constructor_bodies
@@ -170,7 +170,7 @@ linter:
170170
- prefer_is_not_empty
171171
- prefer_is_not_operator
172172
- prefer_iterable_whereType
173-
# - prefer_mixin # Has false positives, see https://github.com/dart-lang/linter/issues/3018
173+
# - prefer_mixin # has false positives, see https://github.com/dart-lang/linter/issues/3018
174174
# - prefer_null_aware_method_calls # "call()" is confusing to people new to the language since it's not documented anywhere
175175
- prefer_null_aware_operators
176176
- prefer_relative_imports
@@ -181,10 +181,10 @@ linter:
181181
- provide_deprecation_message
182182
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
183183
- recursive_getters
184-
# - require_trailing_commas # blocked on https://github.com/dart-lang/sdk/issues/47441
184+
# - require_trailing_commas # would be nice, but requires a lot of manual work: 10,000+ code locations would need to be reformatted by hand after bulk fix is applied
185185
- secure_pubspec_urls
186186
- sized_box_for_whitespace
187-
# - sized_box_shrink_expand # not yet tested
187+
- sized_box_shrink_expand
188188
- slash_for_doc_comments
189189
- sort_child_properties_last
190190
- sort_constructors_first
@@ -222,7 +222,7 @@ linter:
222222
- unsafe_html
223223
- use_build_context_synchronously
224224
# - use_colored_box # not yet tested
225-
# - use_decorated_box # not yet tested
225+
# - use_decorated_box # leads to bugs: DecoratedBox and Container are not equivalent (Container inserts extra padding)
226226
# - use_enums # not yet tested
227227
- use_full_hex_values_for_flutter_colors
228228
- use_function_type_syntax_for_parameters

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ class _BackLabel extends StatelessWidget {
15681568
// null here and unused.
15691569
Widget _buildPreviousTitleWidget(BuildContext context, String? previousTitle, Widget? child) {
15701570
if (previousTitle == null) {
1571-
return const SizedBox(height: 0.0, width: 0.0);
1571+
return const SizedBox.shrink();
15721572
}
15731573

15741574
Text textWidget = Text(
@@ -1602,7 +1602,7 @@ class _BackLabel extends StatelessWidget {
16021602
builder: _buildPreviousTitleWidget,
16031603
);
16041604
} else {
1605-
return const SizedBox(height: 0.0, width: 0.0);
1605+
return const SizedBox.shrink();
16061606
}
16071607
}
16081608
}

packages/flutter/lib/src/material/navigation_rail.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,7 @@ class _RailDestination extends StatelessWidget {
640640
children: <Widget>[
641641
iconPart,
642642
// For semantics when label is not showing,
643-
SizedBox(
644-
width: 0,
645-
height: 0,
643+
SizedBox.shrink(
646644
child: Visibility.maintain(
647645
visible: false,
648646
child: label,

packages/flutter/test/material/app_bar_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,7 @@ void main() {
484484
await tester.pumpWidget(
485485
MaterialApp(
486486
home: Center(
487-
child: SizedBox(
488-
height: 0.0,
489-
width: 0.0,
487+
child: SizedBox.shrink(
490488
child: Scaffold(
491489
appBar: AppBar(
492490
title: const Text('X'),

packages/flutter/test/material/list_tile_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,9 +1616,7 @@ void main() {
16161616

16171617
await tester.pumpWidget(const MaterialApp(
16181618
home: Scaffold(
1619-
body: SizedBox(
1620-
width: 0.0,
1621-
height: 0.0,
1619+
body: SizedBox.shrink(
16221620
child: ListTile(
16231621
key: key,
16241622
tileColor: Colors.green,

packages/flutter/test/material/tooltip_test.dart

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ void main() {
4545
padding: const EdgeInsets.all(5.0),
4646
verticalOffset: 20.0,
4747
preferBelow: false,
48-
child: const SizedBox(
49-
width: 0.0,
50-
height: 0.0,
51-
),
48+
child: const SizedBox.shrink(),
5249
),
5350
),
5451
],
@@ -104,10 +101,7 @@ void main() {
104101
padding: const EdgeInsets.all(5.0),
105102
verticalOffset: 20.0,
106103
preferBelow: false,
107-
child: const SizedBox(
108-
width: 0.0,
109-
height: 0.0,
110-
),
104+
child: const SizedBox.shrink(),
111105
),
112106
),
113107
],
@@ -164,10 +158,7 @@ void main() {
164158
padding: const EdgeInsets.all(5.0),
165159
verticalOffset: 20.0,
166160
preferBelow: false,
167-
child: const SizedBox(
168-
width: 0.0,
169-
height: 0.0,
170-
),
161+
child: const SizedBox.shrink(),
171162
),
172163
),
173164
],
@@ -218,10 +209,7 @@ void main() {
218209
padding: EdgeInsets.zero,
219210
verticalOffset: 100.0,
220211
preferBelow: false,
221-
child: const SizedBox(
222-
width: 0.0,
223-
height: 0.0,
224-
),
212+
child: const SizedBox.shrink(),
225213
),
226214
),
227215
],
@@ -274,10 +262,7 @@ void main() {
274262
padding: EdgeInsets.zero,
275263
verticalOffset: 100.0,
276264
preferBelow: false,
277-
child: const SizedBox(
278-
width: 0.0,
279-
height: 0.0,
280-
),
265+
child: const SizedBox.shrink(),
281266
),
282267
),
283268
],
@@ -341,10 +326,7 @@ void main() {
341326
padding: EdgeInsets.zero,
342327
verticalOffset: 100.0,
343328
preferBelow: true,
344-
child: const SizedBox(
345-
width: 0.0,
346-
height: 0.0,
347-
),
329+
child: const SizedBox.shrink(),
348330
),
349331
),
350332
],
@@ -396,10 +378,7 @@ void main() {
396378
padding: EdgeInsets.zero,
397379
verticalOffset: 10.0,
398380
preferBelow: true,
399-
child: const SizedBox(
400-
width: 0.0,
401-
height: 0.0,
402-
),
381+
child: const SizedBox.shrink(),
403382
),
404383
),
405384
],
@@ -453,10 +432,7 @@ void main() {
453432
padding: EdgeInsets.zero,
454433
verticalOffset: 10.0,
455434
preferBelow: true,
456-
child: const SizedBox(
457-
width: 0.0,
458-
height: 0.0,
459-
),
435+
child: const SizedBox.shrink(),
460436
),
461437
),
462438
],
@@ -559,10 +535,7 @@ void main() {
559535
message: tooltipText,
560536
padding: EdgeInsets.zero,
561537
margin: const EdgeInsets.all(customMarginValue),
562-
child: const SizedBox(
563-
width: 0.0,
564-
height: 0.0,
565-
),
538+
child: const SizedBox.shrink(),
566539
);
567540
},
568541
),
@@ -859,10 +832,7 @@ void main() {
859832
key: tooltipKey,
860833
decoration: customDecoration,
861834
message: tooltipText,
862-
child: const SizedBox(
863-
width: 0.0,
864-
height: 0.0,
865-
),
835+
child: const SizedBox.shrink(),
866836
);
867837
},
868838
),

packages/flutter/test/material/tooltip_theme_test.dart

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,7 @@ void main() {
133133
child: Tooltip(
134134
key: key,
135135
message: tooltipText,
136-
child: const SizedBox(
137-
width: 0.0,
138-
height: 0.0,
139-
),
136+
child: const SizedBox.shrink(),
140137
),
141138
),
142139
],
@@ -191,10 +188,7 @@ void main() {
191188
child: Tooltip(
192189
key: key,
193190
message: tooltipText,
194-
child: const SizedBox(
195-
width: 0.0,
196-
height: 0.0,
197-
),
191+
child: const SizedBox.shrink(),
198192
),
199193
),
200194
],
@@ -251,10 +245,7 @@ void main() {
251245
child: Tooltip(
252246
key: key,
253247
message: tooltipText,
254-
child: const SizedBox(
255-
width: 0.0,
256-
height: 0.0,
257-
),
248+
child: const SizedBox.shrink(),
258249
),
259250
),
260251
],
@@ -320,10 +311,7 @@ void main() {
320311
child: Tooltip(
321312
key: key,
322313
message: tooltipText,
323-
child: const SizedBox(
324-
width: 0.0,
325-
height: 0.0,
326-
),
314+
child: const SizedBox.shrink(),
327315
),
328316
),
329317
],
@@ -391,10 +379,7 @@ void main() {
391379
child: Tooltip(
392380
key: key,
393381
message: tooltipText,
394-
child: const SizedBox(
395-
width: 0.0,
396-
height: 0.0,
397-
),
382+
child: const SizedBox.shrink(),
398383
),
399384
),
400385
],
@@ -448,10 +433,7 @@ void main() {
448433
child: Tooltip(
449434
key: key,
450435
message: tooltipText,
451-
child: const SizedBox(
452-
width: 0.0,
453-
height: 0.0,
454-
),
436+
child: const SizedBox.shrink(),
455437
),
456438
),
457439
],
@@ -500,10 +482,7 @@ void main() {
500482
child: Tooltip(
501483
key: key,
502484
message: tooltipText,
503-
child: const SizedBox(
504-
width: 0.0,
505-
height: 0.0,
506-
),
485+
child: const SizedBox.shrink(),
507486
),
508487
);
509488
},
@@ -556,10 +535,7 @@ void main() {
556535
child: Tooltip(
557536
key: key,
558537
message: tooltipText,
559-
child: const SizedBox(
560-
width: 0.0,
561-
height: 0.0,
562-
),
538+
child: const SizedBox.shrink(),
563539
),
564540
);
565541
},
@@ -715,10 +691,7 @@ void main() {
715691
return Tooltip(
716692
key: key,
717693
message: tooltipText,
718-
child: const SizedBox(
719-
width: 0.0,
720-
height: 0.0,
721-
),
694+
child: const SizedBox.shrink(),
722695
);
723696
},
724697
),
@@ -755,10 +728,7 @@ void main() {
755728
return Tooltip(
756729
key: key,
757730
message: tooltipText,
758-
child: const SizedBox(
759-
width: 0.0,
760-
height: 0.0,
761-
),
731+
child: const SizedBox.shrink(),
762732
);
763733
},
764734
),

packages/flutter/test/rendering/paragraph_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ void main() {
810810
test('assembleSemanticsNode handles empty WidgetSpans that do not yield selection boxes', () {
811811
final TextSpan text = TextSpan(text: '', children: <InlineSpan>[
812812
TextSpan(text: 'A', recognizer: TapGestureRecognizer()..onTap = () {}),
813-
const WidgetSpan(child: SizedBox(width: 0, height: 0)),
813+
const WidgetSpan(child: SizedBox.shrink()),
814814
TextSpan(text: 'C', recognizer: TapGestureRecognizer()..onTap = () {}),
815815
]);
816816
final List<RenderBox> renderBoxes = <RenderBox>[

packages/flutter/test/widgets/column_test.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,7 @@ void main() {
368368
const Key childKey = Key('childKey');
369369

370370
await tester.pumpWidget(Center(
371-
child: SizedBox(
372-
width: 0.0,
373-
height: 0.0,
371+
child: SizedBox.shrink(
374372
child: Column(
375373
mainAxisSize: MainAxisSize.min,
376374
children: const <Widget>[
@@ -760,9 +758,7 @@ void main() {
760758
const Key childKey = Key('childKey');
761759

762760
await tester.pumpWidget(Center(
763-
child: SizedBox(
764-
width: 0.0,
765-
height: 0.0,
761+
child: SizedBox.shrink(
766762
child: Column(
767763
mainAxisSize: MainAxisSize.min,
768764
verticalDirection: VerticalDirection.up,

packages/flutter/test/widgets/custom_paint_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void main() {
147147
expect(target.currentContext!.size, const Size(800.0, 600.0));
148148

149149
await tester.pumpWidget(Center(
150-
child: CustomPaint(key: target, child: const SizedBox(height: 0.0, width: 0.0)),
150+
child: CustomPaint(key: target, child: const SizedBox.shrink()),
151151
));
152152
expect(target.currentContext!.size, Size.zero);
153153

0 commit comments

Comments
 (0)