diff --git a/analysis_options.yaml b/analysis_options.yaml index c97ead7506e..f97380712d8 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -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 diff --git a/packages/flutter/lib/src/cupertino/nav_bar.dart b/packages/flutter/lib/src/cupertino/nav_bar.dart index 976366d8d28..a4c39c422d9 100644 --- a/packages/flutter/lib/src/cupertino/nav_bar.dart +++ b/packages/flutter/lib/src/cupertino/nav_bar.dart @@ -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(); } } } diff --git a/packages/flutter/lib/src/material/navigation_rail.dart b/packages/flutter/lib/src/material/navigation_rail.dart index 27375063d20..a7e14275644 100644 --- a/packages/flutter/lib/src/material/navigation_rail.dart +++ b/packages/flutter/lib/src/material/navigation_rail.dart @@ -640,9 +640,7 @@ class _RailDestination extends StatelessWidget { children: [ iconPart, // For semantics when label is not showing, - SizedBox( - width: 0, - height: 0, + SizedBox.shrink( child: Visibility.maintain( visible: false, child: label, diff --git a/packages/flutter/test/material/app_bar_test.dart b/packages/flutter/test/material/app_bar_test.dart index 97720224b9f..7edf5c5acd4 100644 --- a/packages/flutter/test/material/app_bar_test.dart +++ b/packages/flutter/test/material/app_bar_test.dart @@ -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'), diff --git a/packages/flutter/test/material/list_tile_test.dart b/packages/flutter/test/material/list_tile_test.dart index ab14716b2c7..f0789b4e0f2 100644 --- a/packages/flutter/test/material/list_tile_test.dart +++ b/packages/flutter/test/material/list_tile_test.dart @@ -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, diff --git a/packages/flutter/test/material/tooltip_test.dart b/packages/flutter/test/material/tooltip_test.dart index 98d09e217fc..f0dfdb5e301 100644 --- a/packages/flutter/test/material/tooltip_test.dart +++ b/packages/flutter/test/material/tooltip_test.dart @@ -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(), ); }, ), diff --git a/packages/flutter/test/material/tooltip_theme_test.dart b/packages/flutter/test/material/tooltip_theme_test.dart index 4bfb3046bbe..d26a8d31a2d 100644 --- a/packages/flutter/test/material/tooltip_theme_test.dart +++ b/packages/flutter/test/material/tooltip_theme_test.dart @@ -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(), ); }, ), diff --git a/packages/flutter/test/rendering/paragraph_test.dart b/packages/flutter/test/rendering/paragraph_test.dart index 6ed3da39448..282b540350e 100644 --- a/packages/flutter/test/rendering/paragraph_test.dart +++ b/packages/flutter/test/rendering/paragraph_test.dart @@ -810,7 +810,7 @@ void main() { test('assembleSemanticsNode handles empty WidgetSpans that do not yield selection boxes', () { final TextSpan text = TextSpan(text: '', children: [ 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 renderBoxes = [ diff --git a/packages/flutter/test/widgets/column_test.dart b/packages/flutter/test/widgets/column_test.dart index 6834fb401bb..2a4828e551e 100644 --- a/packages/flutter/test/widgets/column_test.dart +++ b/packages/flutter/test/widgets/column_test.dart @@ -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 [ @@ -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, diff --git a/packages/flutter/test/widgets/custom_paint_test.dart b/packages/flutter/test/widgets/custom_paint_test.dart index d177096c574..933b5b6b4f7 100644 --- a/packages/flutter/test/widgets/custom_paint_test.dart +++ b/packages/flutter/test/widgets/custom_paint_test.dart @@ -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); diff --git a/packages/flutter/test/widgets/display_feature_sub_screen_test.dart b/packages/flutter/test/widgets/display_feature_sub_screen_test.dart index 4e919a8be19..924bed39db5 100644 --- a/packages/flutter/test/widgets/display_feature_sub_screen_test.dart +++ b/packages/flutter/test/widgets/display_feature_sub_screen_test.dart @@ -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, ), ), ), diff --git a/packages/flutter/test/widgets/grid_view_test.dart b/packages/flutter/test/widgets/grid_view_test.dart index bbd8ee923c3..d6c693e92c7 100644 --- a/packages/flutter/test/widgets/grid_view_test.dart +++ b/packages/flutter/test/widgets/grid_view_test.dart @@ -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.generate(20, (int i) { diff --git a/packages/flutter/test/widgets/interactive_viewer_test.dart b/packages/flutter/test/widgets/interactive_viewer_test.dart index 61bad52f2bc..c83ce608051 100644 --- a/packages/flutter/test/widgets/interactive_viewer_test.dart +++ b/packages/flutter/test/widgets/interactive_viewer_test.dart @@ -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(), ), ), ), diff --git a/packages/flutter/test/widgets/list_view_test.dart b/packages/flutter/test/widgets/list_view_test.dart index 66dcaf47d55..64c57106038 100644 --- a/packages/flutter/test/widgets/list_view_test.dart +++ b/packages/flutter/test/widgets/list_view_test.dart @@ -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 [ diff --git a/packages/flutter/test/widgets/page_view_test.dart b/packages/flutter/test/widgets/page_view_test.dart index cce9deaed82..37716e120d3 100644 --- a/packages/flutter/test/widgets/page_view_test.dart +++ b/packages/flutter/test/widgets/page_view_test.dart @@ -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((String state) => Text(state)).toList(), ), diff --git a/packages/flutter/test/widgets/platform_view_test.dart b/packages/flutter/test/widgets/platform_view_test.dart index 900b4d8b448..79542a768b0 100644 --- a/packages/flutter/test/widgets/platform_view_test.dart +++ b/packages/flutter/test/widgets/platform_view_test.dart @@ -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), ), ), diff --git a/packages/flutter/test/widgets/row_test.dart b/packages/flutter/test/widgets/row_test.dart index b1e44787ab2..b189ed4c292 100644 --- a/packages/flutter/test/widgets/row_test.dart +++ b/packages/flutter/test/widgets/row_test.dart @@ -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, diff --git a/packages/flutter/test/widgets/sized_box_test.dart b/packages/flutter/test/widgets/sized_box_test.dart index 1ac27b584fd..4d1d5094e1a 100644 --- a/packages/flutter/test/widgets/sized_box_test.dart +++ b/packages/flutter/test/widgets/sized_box_test.dart @@ -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(), ), ), diff --git a/packages/flutter_driver/test/src/real_tests/extension_test.dart b/packages/flutter_driver/test/src/real_tests/extension_test.dart index 99b0b302909..ca5906c172c 100644 --- a/packages/flutter_driver/test/src/real_tests/extension_test.dart +++ b/packages/flutter_driver/test/src/real_tests/extension_test.dart @@ -1150,9 +1150,7 @@ void main() { home: Material( child: Column(children: const [ Text('Hello ', key: Key('widgetOne')), - SizedBox( - height: 0, - width: 0, + SizedBox.shrink( child: Text('World!', key: Key('widgetTwo')), ), ]),