Unverified Commit fa3777bd authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Enable `sized_box_shrink_expand` lint (#117371)

* Enable  lint

* note about discarded_futures

* note about use_decorated_box

* update note on require_trailing_commas
parent 8289ea62
...@@ -98,7 +98,7 @@ linter: ...@@ -98,7 +98,7 @@ linter:
- deprecated_consistency - deprecated_consistency
# - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib) # - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib)
- directives_ordering - directives_ordering
# - discarded_futures # not yet tested # - discarded_futures # too many false positives, similar to unawaited_futures
# - do_not_use_environment # there are appropriate times to use the environment, especially in our tests and build logic # - do_not_use_environment # there are appropriate times to use the environment, especially in our tests and build logic
- empty_catches - empty_catches
- empty_constructor_bodies - empty_constructor_bodies
...@@ -170,7 +170,7 @@ linter: ...@@ -170,7 +170,7 @@ linter:
- prefer_is_not_empty - prefer_is_not_empty
- prefer_is_not_operator - prefer_is_not_operator
- prefer_iterable_whereType - prefer_iterable_whereType
# - prefer_mixin # Has false positives, see https://github.com/dart-lang/linter/issues/3018 # - prefer_mixin # has false positives, see https://github.com/dart-lang/linter/issues/3018
# - prefer_null_aware_method_calls # "call()" is confusing to people new to the language since it's not documented anywhere # - prefer_null_aware_method_calls # "call()" is confusing to people new to the language since it's not documented anywhere
- prefer_null_aware_operators - prefer_null_aware_operators
- prefer_relative_imports - prefer_relative_imports
...@@ -181,10 +181,10 @@ linter: ...@@ -181,10 +181,10 @@ linter:
- provide_deprecation_message - provide_deprecation_message
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml # - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
- recursive_getters - recursive_getters
# - require_trailing_commas # blocked on https://github.com/dart-lang/sdk/issues/47441 # - 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
- secure_pubspec_urls - secure_pubspec_urls
- sized_box_for_whitespace - sized_box_for_whitespace
# - sized_box_shrink_expand # not yet tested - sized_box_shrink_expand
- slash_for_doc_comments - slash_for_doc_comments
- sort_child_properties_last - sort_child_properties_last
- sort_constructors_first - sort_constructors_first
...@@ -222,7 +222,7 @@ linter: ...@@ -222,7 +222,7 @@ linter:
- unsafe_html - unsafe_html
- use_build_context_synchronously - use_build_context_synchronously
# - use_colored_box # not yet tested # - use_colored_box # not yet tested
# - use_decorated_box # not yet tested # - use_decorated_box # leads to bugs: DecoratedBox and Container are not equivalent (Container inserts extra padding)
# - use_enums # not yet tested # - use_enums # not yet tested
- use_full_hex_values_for_flutter_colors - use_full_hex_values_for_flutter_colors
- use_function_type_syntax_for_parameters - use_function_type_syntax_for_parameters
......
...@@ -1568,7 +1568,7 @@ class _BackLabel extends StatelessWidget { ...@@ -1568,7 +1568,7 @@ class _BackLabel extends StatelessWidget {
// null here and unused. // null here and unused.
Widget _buildPreviousTitleWidget(BuildContext context, String? previousTitle, Widget? child) { Widget _buildPreviousTitleWidget(BuildContext context, String? previousTitle, Widget? child) {
if (previousTitle == null) { if (previousTitle == null) {
return const SizedBox(height: 0.0, width: 0.0); return const SizedBox.shrink();
} }
Text textWidget = Text( Text textWidget = Text(
...@@ -1602,7 +1602,7 @@ class _BackLabel extends StatelessWidget { ...@@ -1602,7 +1602,7 @@ class _BackLabel extends StatelessWidget {
builder: _buildPreviousTitleWidget, builder: _buildPreviousTitleWidget,
); );
} else { } else {
return const SizedBox(height: 0.0, width: 0.0); return const SizedBox.shrink();
} }
} }
} }
......
...@@ -640,9 +640,7 @@ class _RailDestination extends StatelessWidget { ...@@ -640,9 +640,7 @@ class _RailDestination extends StatelessWidget {
children: <Widget>[ children: <Widget>[
iconPart, iconPart,
// For semantics when label is not showing, // For semantics when label is not showing,
SizedBox( SizedBox.shrink(
width: 0,
height: 0,
child: Visibility.maintain( child: Visibility.maintain(
visible: false, visible: false,
child: label, child: label,
......
...@@ -484,9 +484,7 @@ void main() { ...@@ -484,9 +484,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Center( home: Center(
child: SizedBox( child: SizedBox.shrink(
height: 0.0,
width: 0.0,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('X'), title: const Text('X'),
......
...@@ -1616,9 +1616,7 @@ void main() { ...@@ -1616,9 +1616,7 @@ void main() {
await tester.pumpWidget(const MaterialApp( await tester.pumpWidget(const MaterialApp(
home: Scaffold( home: Scaffold(
body: SizedBox( body: SizedBox.shrink(
width: 0.0,
height: 0.0,
child: ListTile( child: ListTile(
key: key, key: key,
tileColor: Colors.green, tileColor: Colors.green,
......
...@@ -45,10 +45,7 @@ void main() { ...@@ -45,10 +45,7 @@ void main() {
padding: const EdgeInsets.all(5.0), padding: const EdgeInsets.all(5.0),
verticalOffset: 20.0, verticalOffset: 20.0,
preferBelow: false, preferBelow: false,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -104,10 +101,7 @@ void main() { ...@@ -104,10 +101,7 @@ void main() {
padding: const EdgeInsets.all(5.0), padding: const EdgeInsets.all(5.0),
verticalOffset: 20.0, verticalOffset: 20.0,
preferBelow: false, preferBelow: false,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -164,10 +158,7 @@ void main() { ...@@ -164,10 +158,7 @@ void main() {
padding: const EdgeInsets.all(5.0), padding: const EdgeInsets.all(5.0),
verticalOffset: 20.0, verticalOffset: 20.0,
preferBelow: false, preferBelow: false,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -218,10 +209,7 @@ void main() { ...@@ -218,10 +209,7 @@ void main() {
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
verticalOffset: 100.0, verticalOffset: 100.0,
preferBelow: false, preferBelow: false,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -274,10 +262,7 @@ void main() { ...@@ -274,10 +262,7 @@ void main() {
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
verticalOffset: 100.0, verticalOffset: 100.0,
preferBelow: false, preferBelow: false,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -341,10 +326,7 @@ void main() { ...@@ -341,10 +326,7 @@ void main() {
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
verticalOffset: 100.0, verticalOffset: 100.0,
preferBelow: true, preferBelow: true,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -396,10 +378,7 @@ void main() { ...@@ -396,10 +378,7 @@ void main() {
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
verticalOffset: 10.0, verticalOffset: 10.0,
preferBelow: true, preferBelow: true,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -453,10 +432,7 @@ void main() { ...@@ -453,10 +432,7 @@ void main() {
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
verticalOffset: 10.0, verticalOffset: 10.0,
preferBelow: true, preferBelow: true,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -559,10 +535,7 @@ void main() { ...@@ -559,10 +535,7 @@ void main() {
message: tooltipText, message: tooltipText,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
margin: const EdgeInsets.all(customMarginValue), margin: const EdgeInsets.all(customMarginValue),
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
); );
}, },
), ),
...@@ -859,10 +832,7 @@ void main() { ...@@ -859,10 +832,7 @@ void main() {
key: tooltipKey, key: tooltipKey,
decoration: customDecoration, decoration: customDecoration,
message: tooltipText, message: tooltipText,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
); );
}, },
), ),
......
...@@ -133,10 +133,7 @@ void main() { ...@@ -133,10 +133,7 @@ void main() {
child: Tooltip( child: Tooltip(
key: key, key: key,
message: tooltipText, message: tooltipText,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -191,10 +188,7 @@ void main() { ...@@ -191,10 +188,7 @@ void main() {
child: Tooltip( child: Tooltip(
key: key, key: key,
message: tooltipText, message: tooltipText,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -251,10 +245,7 @@ void main() { ...@@ -251,10 +245,7 @@ void main() {
child: Tooltip( child: Tooltip(
key: key, key: key,
message: tooltipText, message: tooltipText,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -320,10 +311,7 @@ void main() { ...@@ -320,10 +311,7 @@ void main() {
child: Tooltip( child: Tooltip(
key: key, key: key,
message: tooltipText, message: tooltipText,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -391,10 +379,7 @@ void main() { ...@@ -391,10 +379,7 @@ void main() {
child: Tooltip( child: Tooltip(
key: key, key: key,
message: tooltipText, message: tooltipText,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -448,10 +433,7 @@ void main() { ...@@ -448,10 +433,7 @@ void main() {
child: Tooltip( child: Tooltip(
key: key, key: key,
message: tooltipText, message: tooltipText,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
), ),
], ],
...@@ -500,10 +482,7 @@ void main() { ...@@ -500,10 +482,7 @@ void main() {
child: Tooltip( child: Tooltip(
key: key, key: key,
message: tooltipText, message: tooltipText,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
); );
}, },
...@@ -556,10 +535,7 @@ void main() { ...@@ -556,10 +535,7 @@ void main() {
child: Tooltip( child: Tooltip(
key: key, key: key,
message: tooltipText, message: tooltipText,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
), ),
); );
}, },
...@@ -715,10 +691,7 @@ void main() { ...@@ -715,10 +691,7 @@ void main() {
return Tooltip( return Tooltip(
key: key, key: key,
message: tooltipText, message: tooltipText,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
); );
}, },
), ),
...@@ -755,10 +728,7 @@ void main() { ...@@ -755,10 +728,7 @@ void main() {
return Tooltip( return Tooltip(
key: key, key: key,
message: tooltipText, message: tooltipText,
child: const SizedBox( child: const SizedBox.shrink(),
width: 0.0,
height: 0.0,
),
); );
}, },
), ),
......
...@@ -810,7 +810,7 @@ void main() { ...@@ -810,7 +810,7 @@ void main() {
test('assembleSemanticsNode handles empty WidgetSpans that do not yield selection boxes', () { test('assembleSemanticsNode handles empty WidgetSpans that do not yield selection boxes', () {
final TextSpan text = TextSpan(text: '', children: <InlineSpan>[ final TextSpan text = TextSpan(text: '', children: <InlineSpan>[
TextSpan(text: 'A', recognizer: TapGestureRecognizer()..onTap = () {}), TextSpan(text: 'A', recognizer: TapGestureRecognizer()..onTap = () {}),
const WidgetSpan(child: SizedBox(width: 0, height: 0)), const WidgetSpan(child: SizedBox.shrink()),
TextSpan(text: 'C', recognizer: TapGestureRecognizer()..onTap = () {}), TextSpan(text: 'C', recognizer: TapGestureRecognizer()..onTap = () {}),
]); ]);
final List<RenderBox> renderBoxes = <RenderBox>[ final List<RenderBox> renderBoxes = <RenderBox>[
......
...@@ -368,9 +368,7 @@ void main() { ...@@ -368,9 +368,7 @@ void main() {
const Key childKey = Key('childKey'); const Key childKey = Key('childKey');
await tester.pumpWidget(Center( await tester.pumpWidget(Center(
child: SizedBox( child: SizedBox.shrink(
width: 0.0,
height: 0.0,
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: const <Widget>[ children: const <Widget>[
...@@ -760,9 +758,7 @@ void main() { ...@@ -760,9 +758,7 @@ void main() {
const Key childKey = Key('childKey'); const Key childKey = Key('childKey');
await tester.pumpWidget(Center( await tester.pumpWidget(Center(
child: SizedBox( child: SizedBox.shrink(
width: 0.0,
height: 0.0,
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
verticalDirection: VerticalDirection.up, verticalDirection: VerticalDirection.up,
......
...@@ -147,7 +147,7 @@ void main() { ...@@ -147,7 +147,7 @@ void main() {
expect(target.currentContext!.size, const Size(800.0, 600.0)); expect(target.currentContext!.size, const Size(800.0, 600.0));
await tester.pumpWidget(Center( await tester.pumpWidget(Center(
child: CustomPaint(key: target, child: const SizedBox(height: 0.0, width: 0.0)), child: CustomPaint(key: target, child: const SizedBox.shrink()),
)); ));
expect(target.currentContext!.size, Size.zero); expect(target.currentContext!.size, Size.zero);
......
...@@ -25,10 +25,8 @@ void main() { ...@@ -25,10 +25,8 @@ void main() {
MediaQuery( MediaQuery(
data: mediaQuery, data: mediaQuery,
child: const DisplayFeatureSubScreen( child: const DisplayFeatureSubScreen(
child: SizedBox( child: SizedBox.expand(
key: childKey, key: childKey,
width: double.infinity,
height: double.infinity,
), ),
), ),
), ),
...@@ -56,10 +54,8 @@ void main() { ...@@ -56,10 +54,8 @@ void main() {
data: mediaQuery, data: mediaQuery,
child: const DisplayFeatureSubScreen( child: const DisplayFeatureSubScreen(
anchorPoint: Offset(600, 300), anchorPoint: Offset(600, 300),
child: SizedBox( child: SizedBox.expand(
key: childKey, key: childKey,
width: double.infinity,
height: double.infinity,
), ),
), ),
), ),
...@@ -89,10 +85,8 @@ void main() { ...@@ -89,10 +85,8 @@ void main() {
data: mediaQuery, data: mediaQuery,
child: const DisplayFeatureSubScreen( child: const DisplayFeatureSubScreen(
anchorPoint: Offset.infinite, anchorPoint: Offset.infinite,
child: SizedBox( child: SizedBox.expand(
key: childKey, key: childKey,
width: double.infinity,
height: double.infinity,
), ),
), ),
), ),
...@@ -122,10 +116,8 @@ void main() { ...@@ -122,10 +116,8 @@ void main() {
data: mediaQuery, data: mediaQuery,
child: const DisplayFeatureSubScreen( child: const DisplayFeatureSubScreen(
anchorPoint: Offset(1000, 1000), anchorPoint: Offset(1000, 1000),
child: SizedBox( child: SizedBox.expand(
key: childKey, key: childKey,
width: double.infinity,
height: double.infinity,
), ),
), ),
), ),
...@@ -159,10 +151,8 @@ void main() { ...@@ -159,10 +151,8 @@ void main() {
data: mediaQuery, data: mediaQuery,
child: const DisplayFeatureSubScreen( child: const DisplayFeatureSubScreen(
anchorPoint: Offset(1000, 1000), anchorPoint: Offset(1000, 1000),
child: SizedBox( child: SizedBox.expand(
key: childKey, key: childKey,
width: double.infinity,
height: double.infinity,
), ),
), ),
), ),
...@@ -204,10 +194,8 @@ void main() { ...@@ -204,10 +194,8 @@ void main() {
child: const Directionality( child: const Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: DisplayFeatureSubScreen( child: DisplayFeatureSubScreen(
child: SizedBox( child: SizedBox.expand(
key: childKey, key: childKey,
width: double.infinity,
height: double.infinity,
), ),
), ),
), ),
...@@ -238,10 +226,8 @@ void main() { ...@@ -238,10 +226,8 @@ void main() {
data: mediaQuery, data: mediaQuery,
child: const DisplayFeatureSubScreen( child: const DisplayFeatureSubScreen(
anchorPoint: Offset(1000, 1000), anchorPoint: Offset(1000, 1000),
child: SizedBox( child: SizedBox.expand(
key: childKey, key: childKey,
width: double.infinity,
height: double.infinity,
), ),
), ),
), ),
......
...@@ -475,9 +475,7 @@ void main() { ...@@ -475,9 +475,7 @@ void main() {
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Center( child: Center(
child: SizedBox( child: SizedBox.shrink(
width: 0.0,
height: 0.0,
child: GridView.count( child: GridView.count(
crossAxisCount: 4, crossAxisCount: 4,
children: List<Widget>.generate(20, (int i) { children: List<Widget>.generate(20, (int i) {
......
...@@ -207,7 +207,7 @@ void main() { ...@@ -207,7 +207,7 @@ void main() {
constrained: false, constrained: false,
scaleEnabled: false, scaleEnabled: false,
transformationController: transformationController, transformationController: transformationController,
child: const SizedBox(width: 0.0, height: 0.0), child: const SizedBox.shrink(),
), ),
), ),
), ),
......
...@@ -347,9 +347,7 @@ void main() { ...@@ -347,9 +347,7 @@ void main() {
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Center( child: Center(
child: SizedBox( child: SizedBox.shrink(
width: 0.0,
height: 0.0,
child: ListView( child: ListView(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
children: const <Widget>[ children: const <Widget>[
......
...@@ -418,9 +418,7 @@ void main() { ...@@ -418,9 +418,7 @@ void main() {
await tester.pumpWidget(Directionality( await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Center( child: Center(
child: SizedBox( child: SizedBox.shrink(
width: 0.0,
height: 0.0,
child: PageView( child: PageView(
children: kStates.map<Widget>((String state) => Text(state)).toList(), children: kStates.map<Widget>((String state) => Text(state)).toList(),
), ),
......
...@@ -96,9 +96,7 @@ void main() { ...@@ -96,9 +96,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
const Center( const Center(
child: SizedBox( child: SizedBox.shrink(
width: 0.0,
height: 0.0,
child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr), child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr),
), ),
), ),
......
...@@ -285,9 +285,7 @@ void main() { ...@@ -285,9 +285,7 @@ void main() {
const Key childKey = Key('childKey'); const Key childKey = Key('childKey');
await tester.pumpWidget(Center( await tester.pumpWidget(Center(
child: SizedBox( child: SizedBox.shrink(
width: 0.0,
height: 0.0,
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
...@@ -707,9 +705,7 @@ void main() { ...@@ -707,9 +705,7 @@ void main() {
const Key childKey = Key('childKey'); const Key childKey = Key('childKey');
await tester.pumpWidget(Center( await tester.pumpWidget(Center(
child: SizedBox( child: SizedBox.shrink(
width: 0.0,
height: 0.0,
child: Row( child: Row(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
...@@ -1130,9 +1126,7 @@ void main() { ...@@ -1130,9 +1126,7 @@ void main() {
const Key childKey = Key('childKey'); const Key childKey = Key('childKey');
await tester.pumpWidget(Center( await tester.pumpWidget(Center(
child: SizedBox( child: SizedBox.shrink(
width: 0.0,
height: 0.0,
child: Row( child: Row(
textDirection: TextDirection.rtl, textDirection: TextDirection.rtl,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
......
...@@ -61,10 +61,8 @@ void main() { ...@@ -61,10 +61,8 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
Center( Center(
child: SizedBox( child: SizedBox.shrink(
key: patient, key: patient,
width: 0.0,
height: 0.0,
), ),
), ),
); );
...@@ -137,10 +135,8 @@ void main() { ...@@ -137,10 +135,8 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
Center( Center(
child: SizedBox( child: SizedBox.shrink(
key: patient, key: patient,
width: 0.0,
height: 0.0,
child: Container(), child: Container(),
), ),
), ),
......
...@@ -1150,9 +1150,7 @@ void main() { ...@@ -1150,9 +1150,7 @@ void main() {
home: Material( home: Material(
child: Column(children: const<Widget> [ child: Column(children: const<Widget> [
Text('Hello ', key: Key('widgetOne')), Text('Hello ', key: Key('widgetOne')),
SizedBox( SizedBox.shrink(
height: 0,
width: 0,
child: Text('World!', key: Key('widgetTwo')), child: Text('World!', key: Key('widgetTwo')),
), ),
]), ]),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment