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:
- deprecated_consistency
# - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib)
- 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
- empty_catches
- empty_constructor_bodies
......@@ -170,7 +170,7 @@ linter:
- prefer_is_not_empty
- prefer_is_not_operator
- 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_operators
- prefer_relative_imports
......@@ -181,10 +181,10 @@ linter:
- provide_deprecation_message
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
- 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
- sized_box_for_whitespace
# - sized_box_shrink_expand # not yet tested
- sized_box_shrink_expand
- slash_for_doc_comments
- sort_child_properties_last
- sort_constructors_first
......@@ -222,7 +222,7 @@ linter:
- unsafe_html
- use_build_context_synchronously
# - 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_full_hex_values_for_flutter_colors
- use_function_type_syntax_for_parameters
......
......@@ -1568,7 +1568,7 @@ class _BackLabel extends StatelessWidget {
// null here and unused.
Widget _buildPreviousTitleWidget(BuildContext context, String? previousTitle, Widget? child) {
if (previousTitle == null) {
return const SizedBox(height: 0.0, width: 0.0);
return const SizedBox.shrink();
}
Text textWidget = Text(
......@@ -1602,7 +1602,7 @@ class _BackLabel extends StatelessWidget {
builder: _buildPreviousTitleWidget,
);
} else {
return const SizedBox(height: 0.0, width: 0.0);
return const SizedBox.shrink();
}
}
}
......
......@@ -640,9 +640,7 @@ class _RailDestination extends StatelessWidget {
children: <Widget>[
iconPart,
// For semantics when label is not showing,
SizedBox(
width: 0,
height: 0,
SizedBox.shrink(
child: Visibility.maintain(
visible: false,
child: label,
......
......@@ -484,9 +484,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
home: Center(
child: SizedBox(
height: 0.0,
width: 0.0,
child: SizedBox.shrink(
child: Scaffold(
appBar: AppBar(
title: const Text('X'),
......
......@@ -1616,9 +1616,7 @@ void main() {
await tester.pumpWidget(const MaterialApp(
home: Scaffold(
body: SizedBox(
width: 0.0,
height: 0.0,
body: SizedBox.shrink(
child: ListTile(
key: key,
tileColor: Colors.green,
......
......@@ -45,10 +45,7 @@ void main() {
padding: const EdgeInsets.all(5.0),
verticalOffset: 20.0,
preferBelow: false,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -104,10 +101,7 @@ void main() {
padding: const EdgeInsets.all(5.0),
verticalOffset: 20.0,
preferBelow: false,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -164,10 +158,7 @@ void main() {
padding: const EdgeInsets.all(5.0),
verticalOffset: 20.0,
preferBelow: false,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -218,10 +209,7 @@ void main() {
padding: EdgeInsets.zero,
verticalOffset: 100.0,
preferBelow: false,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -274,10 +262,7 @@ void main() {
padding: EdgeInsets.zero,
verticalOffset: 100.0,
preferBelow: false,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -341,10 +326,7 @@ void main() {
padding: EdgeInsets.zero,
verticalOffset: 100.0,
preferBelow: true,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -396,10 +378,7 @@ void main() {
padding: EdgeInsets.zero,
verticalOffset: 10.0,
preferBelow: true,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -453,10 +432,7 @@ void main() {
padding: EdgeInsets.zero,
verticalOffset: 10.0,
preferBelow: true,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -559,10 +535,7 @@ void main() {
message: tooltipText,
padding: EdgeInsets.zero,
margin: const EdgeInsets.all(customMarginValue),
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
);
},
),
......@@ -859,10 +832,7 @@ void main() {
key: tooltipKey,
decoration: customDecoration,
message: tooltipText,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
);
},
),
......
......@@ -133,10 +133,7 @@ void main() {
child: Tooltip(
key: key,
message: tooltipText,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -191,10 +188,7 @@ void main() {
child: Tooltip(
key: key,
message: tooltipText,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -251,10 +245,7 @@ void main() {
child: Tooltip(
key: key,
message: tooltipText,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -320,10 +311,7 @@ void main() {
child: Tooltip(
key: key,
message: tooltipText,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -391,10 +379,7 @@ void main() {
child: Tooltip(
key: key,
message: tooltipText,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -448,10 +433,7 @@ void main() {
child: Tooltip(
key: key,
message: tooltipText,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
),
],
......@@ -500,10 +482,7 @@ void main() {
child: Tooltip(
key: key,
message: tooltipText,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
);
},
......@@ -556,10 +535,7 @@ void main() {
child: Tooltip(
key: key,
message: tooltipText,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
),
);
},
......@@ -715,10 +691,7 @@ void main() {
return Tooltip(
key: key,
message: tooltipText,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
);
},
),
......@@ -755,10 +728,7 @@ void main() {
return Tooltip(
key: key,
message: tooltipText,
child: const SizedBox(
width: 0.0,
height: 0.0,
),
child: const SizedBox.shrink(),
);
},
),
......
......@@ -810,7 +810,7 @@ void main() {
test('assembleSemanticsNode handles empty WidgetSpans that do not yield selection boxes', () {
final TextSpan text = TextSpan(text: '', children: <InlineSpan>[
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 = () {}),
]);
final List<RenderBox> renderBoxes = <RenderBox>[
......
......@@ -368,9 +368,7 @@ void main() {
const Key childKey = Key('childKey');
await tester.pumpWidget(Center(
child: SizedBox(
width: 0.0,
height: 0.0,
child: SizedBox.shrink(
child: Column(
mainAxisSize: MainAxisSize.min,
children: const <Widget>[
......@@ -760,9 +758,7 @@ void main() {
const Key childKey = Key('childKey');
await tester.pumpWidget(Center(
child: SizedBox(
width: 0.0,
height: 0.0,
child: SizedBox.shrink(
child: Column(
mainAxisSize: MainAxisSize.min,
verticalDirection: VerticalDirection.up,
......
......@@ -147,7 +147,7 @@ void main() {
expect(target.currentContext!.size, const Size(800.0, 600.0));
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);
......
......@@ -25,10 +25,8 @@ void main() {
MediaQuery(
data: mediaQuery,
child: const DisplayFeatureSubScreen(
child: SizedBox(
child: SizedBox.expand(
key: childKey,
width: double.infinity,
height: double.infinity,
),
),
),
......@@ -56,10 +54,8 @@ void main() {
data: mediaQuery,
child: const DisplayFeatureSubScreen(
anchorPoint: Offset(600, 300),
child: SizedBox(
child: SizedBox.expand(
key: childKey,
width: double.infinity,
height: double.infinity,
),
),
),
......@@ -89,10 +85,8 @@ void main() {
data: mediaQuery,
child: const DisplayFeatureSubScreen(
anchorPoint: Offset.infinite,
child: SizedBox(
child: SizedBox.expand(
key: childKey,
width: double.infinity,
height: double.infinity,
),
),
),
......@@ -122,10 +116,8 @@ void main() {
data: mediaQuery,
child: const DisplayFeatureSubScreen(
anchorPoint: Offset(1000, 1000),
child: SizedBox(
child: SizedBox.expand(
key: childKey,
width: double.infinity,
height: double.infinity,
),
),
),
......@@ -159,10 +151,8 @@ void main() {
data: mediaQuery,
child: const DisplayFeatureSubScreen(
anchorPoint: Offset(1000, 1000),
child: SizedBox(
child: SizedBox.expand(
key: childKey,
width: double.infinity,
height: double.infinity,
),
),
),
......@@ -204,10 +194,8 @@ void main() {
child: const Directionality(
textDirection: TextDirection.ltr,
child: DisplayFeatureSubScreen(
child: SizedBox(
child: SizedBox.expand(
key: childKey,
width: double.infinity,
height: double.infinity,
),
),
),
......@@ -238,10 +226,8 @@ void main() {
data: mediaQuery,
child: const DisplayFeatureSubScreen(
anchorPoint: Offset(1000, 1000),
child: SizedBox(
child: SizedBox.expand(
key: childKey,
width: double.infinity,
height: double.infinity,
),
),
),
......
......@@ -475,9 +475,7 @@ void main() {
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: SizedBox(
width: 0.0,
height: 0.0,
child: SizedBox.shrink(
child: GridView.count(
crossAxisCount: 4,
children: List<Widget>.generate(20, (int i) {
......
......@@ -207,7 +207,7 @@ void main() {
constrained: false,
scaleEnabled: false,
transformationController: transformationController,
child: const SizedBox(width: 0.0, height: 0.0),
child: const SizedBox.shrink(),
),
),
),
......
......@@ -347,9 +347,7 @@ void main() {
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: SizedBox(
width: 0.0,
height: 0.0,
child: SizedBox.shrink(
child: ListView(
padding: const EdgeInsets.all(8.0),
children: const <Widget>[
......
......@@ -418,9 +418,7 @@ void main() {
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: SizedBox(
width: 0.0,
height: 0.0,
child: SizedBox.shrink(
child: PageView(
children: kStates.map<Widget>((String state) => Text(state)).toList(),
),
......
......@@ -96,9 +96,7 @@ void main() {
await tester.pumpWidget(
const Center(
child: SizedBox(
width: 0.0,
height: 0.0,
child: SizedBox.shrink(
child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr),
),
),
......
......@@ -285,9 +285,7 @@ void main() {
const Key childKey = Key('childKey');
await tester.pumpWidget(Center(
child: SizedBox(
width: 0.0,
height: 0.0,
child: SizedBox.shrink(
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
......@@ -707,9 +705,7 @@ void main() {
const Key childKey = Key('childKey');
await tester.pumpWidget(Center(
child: SizedBox(
width: 0.0,
height: 0.0,
child: SizedBox.shrink(
child: Row(
textDirection: TextDirection.ltr,
mainAxisSize: MainAxisSize.min,
......@@ -1130,9 +1126,7 @@ void main() {
const Key childKey = Key('childKey');
await tester.pumpWidget(Center(
child: SizedBox(
width: 0.0,
height: 0.0,
child: SizedBox.shrink(
child: Row(
textDirection: TextDirection.rtl,
mainAxisSize: MainAxisSize.min,
......
......@@ -61,10 +61,8 @@ void main() {
await tester.pumpWidget(
Center(
child: SizedBox(
child: SizedBox.shrink(
key: patient,
width: 0.0,
height: 0.0,
),
),
);
......@@ -137,10 +135,8 @@ void main() {
await tester.pumpWidget(
Center(
child: SizedBox(
child: SizedBox.shrink(
key: patient,
width: 0.0,
height: 0.0,
child: Container(),
),
),
......
......@@ -1150,9 +1150,7 @@ void main() {
home: Material(
child: Column(children: const<Widget> [
Text('Hello ', key: Key('widgetOne')),
SizedBox(
height: 0,
width: 0,
SizedBox.shrink(
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