diff --git a/packages/flutter/lib/src/cupertino/context_menu.dart b/packages/flutter/lib/src/cupertino/context_menu.dart index 39216fc56a..94223f51b5 100644 --- a/packages/flutter/lib/src/cupertino/context_menu.dart +++ b/packages/flutter/lib/src/cupertino/context_menu.dart @@ -738,8 +738,8 @@ class _ContextMenuRoute extends PopupRoute { // buildTransitions as child, the idea being that buildTransitions will // animate the entire page into the scene. In the case of _ContextMenuRoute, // two individual pieces of the page are animated into the scene in - // buildTransitions, and a Container is returned here. - return Container(); + // buildTransitions, and a SizedBox.shrink() is returned here. + return const SizedBox.shrink(); } @override diff --git a/packages/flutter/lib/src/cupertino/desktop_text_selection.dart b/packages/flutter/lib/src/cupertino/desktop_text_selection.dart index 6c129c6f68..9711d66f3a 100644 --- a/packages/flutter/lib/src/cupertino/desktop_text_selection.dart +++ b/packages/flutter/lib/src/cupertino/desktop_text_selection.dart @@ -153,7 +153,7 @@ class _CupertinoDesktopTextSelectionControlsToolbarState extends State<_Cupertin Widget build(BuildContext context) { // Don't render the menu until the state of the clipboard is known. if (widget.handlePaste != null && widget.clipboardStatus?.value == ClipboardStatus.unknown) { - return const SizedBox(width: 0.0, height: 0.0); + return const SizedBox.shrink(); } assert(debugCheckHasMediaQuery(context)); @@ -203,7 +203,7 @@ class _CupertinoDesktopTextSelectionControlsToolbarState extends State<_Cupertin // If there is no option available, build an empty widget. if (items.isEmpty) { - return const SizedBox(width: 0.0, height: 0.0); + return const SizedBox.shrink(); } return _CupertinoDesktopTextSelectionToolbar( diff --git a/packages/flutter/lib/src/cupertino/dialog.dart b/packages/flutter/lib/src/cupertino/dialog.dart index 435cf2b478..33a77f0e1d 100644 --- a/packages/flutter/lib/src/cupertino/dialog.dart +++ b/packages/flutter/lib/src/cupertino/dialog.dart @@ -1389,7 +1389,7 @@ class _CupertinoAlertContentSection extends StatelessWidget { if (title == null && message == null) { return SingleChildScrollView( controller: scrollController, - child: const SizedBox(width: 0.0, height: 0.0), + child: const SizedBox.shrink(), ); } diff --git a/packages/flutter/lib/src/cupertino/refresh.dart b/packages/flutter/lib/src/cupertino/refresh.dart index dd2622e1dc..351044a855 100644 --- a/packages/flutter/lib/src/cupertino/refresh.dart +++ b/packages/flutter/lib/src/cupertino/refresh.dart @@ -422,7 +422,7 @@ class CupertinoSliverRefreshControl extends StatefulWidget { return CupertinoActivityIndicator(radius: radius * percentageComplete); case RefreshIndicatorMode.inactive: // Anything else doesn't show anything. - return Container(); + return const SizedBox.shrink(); } } diff --git a/packages/flutter/lib/src/cupertino/tab_scaffold.dart b/packages/flutter/lib/src/cupertino/tab_scaffold.dart index 3838a0410a..4779ce55e9 100644 --- a/packages/flutter/lib/src/cupertino/tab_scaffold.dart +++ b/packages/flutter/lib/src/cupertino/tab_scaffold.dart @@ -504,7 +504,7 @@ class _TabSwitchingViewState extends State<_TabSwitchingView> { child: FocusScope( node: tabFocusNodes[index], child: Builder(builder: (BuildContext context) { - return shouldBuildTab[index] ? widget.tabBuilder(context, index) : Container(); + return shouldBuildTab[index] ? widget.tabBuilder(context, index) : const SizedBox.shrink(); }), ), ), diff --git a/packages/flutter/lib/src/cupertino/text_selection.dart b/packages/flutter/lib/src/cupertino/text_selection.dart index 3bebdac761..67d004a50e 100644 --- a/packages/flutter/lib/src/cupertino/text_selection.dart +++ b/packages/flutter/lib/src/cupertino/text_selection.dart @@ -82,7 +82,7 @@ class _CupertinoTextSelectionControlsToolbarState extends State<_CupertinoTextSe Widget build(BuildContext context) { // Don't render the menu until the state of the clipboard is known. if (widget.handlePaste != null && widget.clipboardStatus?.value == ClipboardStatus.unknown) { - return const SizedBox(width: 0.0, height: 0.0); + return const SizedBox.shrink(); } assert(debugCheckHasMediaQuery(context)); @@ -147,7 +147,7 @@ class _CupertinoTextSelectionControlsToolbarState extends State<_CupertinoTextSe // If there is no option available, build an empty widget. if (items.isEmpty) { - return const SizedBox(width: 0.0, height: 0.0); + return const SizedBox.shrink(); } return CupertinoTextSelectionToolbar( @@ -266,7 +266,7 @@ class CupertinoTextSelectionControls extends TextSelectionControls { ); // iOS doesn't draw anything for collapsed selections. case TextSelectionHandleType.collapsed: - return const SizedBox(); + return const SizedBox.shrink(); } } diff --git a/packages/flutter/lib/src/material/about.dart b/packages/flutter/lib/src/material/about.dart index 7247d61bba..be7ec03914 100644 --- a/packages/flutter/lib/src/material/about.dart +++ b/packages/flutter/lib/src/material/about.dart @@ -1451,7 +1451,7 @@ class _DetailView extends StatelessWidget { @override Widget build(BuildContext context) { if (_arguments == null) { - return Container(); + return const SizedBox.shrink(); } final double screenHeight = MediaQuery.of(context).size.height; final double minHeight = (screenHeight - kToolbarHeight) / screenHeight; diff --git a/packages/flutter/lib/src/material/data_table.dart b/packages/flutter/lib/src/material/data_table.dart index 82f40ace62..7cea784123 100644 --- a/packages/flutter/lib/src/material/data_table.dart +++ b/packages/flutter/lib/src/material/data_table.dart @@ -237,7 +237,7 @@ class DataCell { }) : assert(child != null); /// A cell that has no content and has zero width and height. - static const DataCell empty = DataCell(SizedBox(width: 0.0, height: 0.0)); + static const DataCell empty = DataCell(SizedBox.shrink()); /// The data for the row. /// diff --git a/packages/flutter/lib/src/material/desktop_text_selection.dart b/packages/flutter/lib/src/material/desktop_text_selection.dart index d5e1802def..fbe6848d45 100644 --- a/packages/flutter/lib/src/material/desktop_text_selection.dart +++ b/packages/flutter/lib/src/material/desktop_text_selection.dart @@ -153,7 +153,7 @@ class _DesktopTextSelectionControlsToolbarState extends State<_DesktopTextSelect // Don't render the menu until the state of the clipboard is known. if (widget.handlePaste != null && widget.clipboardStatus?.value == ClipboardStatus.unknown) { - return const SizedBox(width: 0.0, height: 0.0); + return const SizedBox.shrink(); } final MediaQueryData mediaQuery = MediaQuery.of(context); @@ -196,7 +196,7 @@ class _DesktopTextSelectionControlsToolbarState extends State<_DesktopTextSelect // If there is no option available, build an empty widget. if (items.isEmpty) { - return const SizedBox(width: 0.0, height: 0.0); + return const SizedBox.shrink(); } return _DesktopTextSelectionToolbar( diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index c8e7b151da..4fe46d78ca 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -1424,7 +1424,7 @@ class _DropdownButtonState extends State> with WidgetsBindi // display the hint or nothing at all. final Widget innerItemsWidget; if (items.isEmpty) { - innerItemsWidget = Container(); + innerItemsWidget = const SizedBox.shrink(); } else { innerItemsWidget = IndexedStack( index: _selectedIndex ?? hintIndex, diff --git a/packages/flutter/lib/src/material/ink_decoration.dart b/packages/flutter/lib/src/material/ink_decoration.dart index 8529cfbc56..0ac337a7b2 100644 --- a/packages/flutter/lib/src/material/ink_decoration.dart +++ b/packages/flutter/lib/src/material/ink_decoration.dart @@ -292,7 +292,7 @@ class _InkState extends State { _ink!.decoration = widget.decoration; _ink!.configuration = createLocalImageConfiguration(context); } - return widget.child ?? Container(); + return widget.child ?? const SizedBox(); } @override diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 48def3297f..debcfd9c49 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -319,7 +319,7 @@ class _HelperError extends StatefulWidget { class _HelperErrorState extends State<_HelperError> with SingleTickerProviderStateMixin { // If the height of this widget and the counter are zero ("empty") at // layout time, no space is allocated for the subtext. - static const Widget empty = SizedBox(); + static const Widget empty = SizedBox.shrink(); late AnimationController _controller; Widget? _helper; diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index a3fe58b535..b8a61f6899 100644 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -641,7 +641,7 @@ class _StepperState extends State with TickerProviderStateMixin { child: widget.steps[index].label!, ); } - return const SizedBox(); + return const SizedBox.shrink(); } Widget _buildVerticalHeader(int index) { diff --git a/packages/flutter/lib/src/material/text_selection.dart b/packages/flutter/lib/src/material/text_selection.dart index 33da727aec..9b4aa1e6fe 100644 --- a/packages/flutter/lib/src/material/text_selection.dart +++ b/packages/flutter/lib/src/material/text_selection.dart @@ -250,7 +250,7 @@ class _TextSelectionControlsToolbarState extends State<_TextSelectionControlsToo // If there is no option available, build an empty widget. if (itemDatas.isEmpty) { - return const SizedBox(width: 0.0, height: 0.0); + return const SizedBox.shrink(); } return TextSelectionToolbar( diff --git a/packages/flutter/lib/src/material/tooltip.dart b/packages/flutter/lib/src/material/tooltip.dart index f5853f0d79..2cccb853bd 100644 --- a/packages/flutter/lib/src/material/tooltip.dart +++ b/packages/flutter/lib/src/material/tooltip.dart @@ -696,7 +696,7 @@ class TooltipState extends State with SingleTickerProviderStateMixin { // the empty black container so just return the wrapped child as is or // empty container if child is not specified. if (_tooltipMessage.isEmpty) { - return widget.child ?? const SizedBox(); + return widget.child ?? const SizedBox.shrink(); } assert(debugCheckHasOverlay(context)); final ThemeData theme = Theme.of(context); diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index de40b05f26..d0ecb09037 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -3829,10 +3829,10 @@ class EditableTextState extends State with AutomaticKeepAliveClien final int placeholderLocation = _value.text.length - _placeholderLocation; if (_isMultiline) { // The zero size placeholder here allows the line to break and keep the caret on the first line. - placeholders.add(const _ScribblePlaceholder(child: SizedBox(), size: Size.zero)); - placeholders.add(_ScribblePlaceholder(child: const SizedBox(), size: Size(renderEditable.size.width, 0.0))); + placeholders.add(const _ScribblePlaceholder(child: SizedBox.shrink(), size: Size.zero)); + placeholders.add(_ScribblePlaceholder(child: const SizedBox.shrink(), size: Size(renderEditable.size.width, 0.0))); } else { - placeholders.add(const _ScribblePlaceholder(child: SizedBox(), size: Size(100.0, 0.0))); + placeholders.add(const _ScribblePlaceholder(child: SizedBox.shrink(), size: Size(100.0, 0.0))); } return TextSpan(style: widget.style, children: [ TextSpan(text: _value.text.substring(0, placeholderLocation)), diff --git a/packages/flutter/lib/src/widgets/localizations.dart b/packages/flutter/lib/src/widgets/localizations.dart index 5e22744ee3..8d6e4230dc 100644 --- a/packages/flutter/lib/src/widgets/localizations.dart +++ b/packages/flutter/lib/src/widgets/localizations.dart @@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'basic.dart'; -import 'container.dart'; import 'debug.dart'; import 'framework.dart'; @@ -598,7 +597,7 @@ class _LocalizationsState extends State { @override Widget build(BuildContext context) { if (_locale == null) { - return Container(); + return const SizedBox.shrink(); } return Semantics( textDirection: _textDirection, diff --git a/packages/flutter/lib/src/widgets/text_selection.dart b/packages/flutter/lib/src/widgets/text_selection.dart index 96076ae457..4214070f56 100644 --- a/packages/flutter/lib/src/widgets/text_selection.dart +++ b/packages/flutter/lib/src/widgets/text_selection.dart @@ -1156,7 +1156,7 @@ class SelectionOverlay { final Widget handle; final TextSelectionControls? selectionControls = this.selectionControls; if (selectionControls == null) { - handle = Container(); + handle = const SizedBox.shrink(); } else { handle = _SelectionHandleOverlay( type: _startHandleType, @@ -1183,7 +1183,7 @@ class SelectionOverlay { final TextSelectionControls? selectionControls = this.selectionControls; if (selectionControls == null || _startHandleType == TextSelectionHandleType.collapsed) { // Hide the second handle when collapsed. - handle = Container(); + handle = const SizedBox.shrink(); } else { handle = _SelectionHandleOverlay( type: _endHandleType, @@ -1207,7 +1207,7 @@ class SelectionOverlay { Widget _buildToolbar(BuildContext context) { if (selectionControls == null) { - return Container(); + return const SizedBox.shrink(); } final RenderBox renderBox = this.context.findRenderObject()! as RenderBox; diff --git a/packages/flutter/test/material/ink_paint_test.dart b/packages/flutter/test/material/ink_paint_test.dart index 083a72b2c0..8a52797f92 100644 --- a/packages/flutter/test/material/ink_paint_test.dart +++ b/packages/flutter/test/material/ink_paint_test.dart @@ -9,14 +9,19 @@ import 'package:flutter_test/flutter_test.dart'; import '../rendering/mock_canvas.dart'; void main() { - testWidgets('The Ink widget renders a Container by default', (WidgetTester tester) async { + testWidgets('The Ink widget renders a SizedBox by default', (WidgetTester tester) async { await tester.pumpWidget( Material( child: Ink(), ), ); - expect(tester.getSize(find.byType(Container)).height, 600.0); - expect(tester.getSize(find.byType(Container)).width, 800.0); + Finder sizedBox = find.descendant( + of: find.byType(Ink), + matching: find.byType(SizedBox), + ); + expect(sizedBox, findsOneWidget); + expect(tester.getSize(sizedBox).height, 600.0); + expect(tester.getSize(sizedBox).width, 800.0); const double height = 150.0; const double width = 200.0; @@ -31,8 +36,13 @@ void main() { ), ); await tester.pumpAndSettle(); - expect(tester.getSize(find.byType(Container)).height, height); - expect(tester.getSize(find.byType(Container)).width, width); + sizedBox = find.descendant( + of: find.byType(Ink), + matching: find.byType(SizedBox), + ); + expect(sizedBox, findsNWidgets(2)); + expect(tester.getSize(sizedBox.at(0)).height, height); + expect(tester.getSize(sizedBox.at(0)).width, width); }); testWidgets('The InkWell widget renders an ink splash', (WidgetTester tester) async {