Unverified Commit 75ee4403 authored by Tomasz Gucio's avatar Tomasz Gucio Committed by GitHub

Replace empty Container with const SizedBox (#108672)

parent 30baf95a
...@@ -738,8 +738,8 @@ class _ContextMenuRoute<T> extends PopupRoute<T> { ...@@ -738,8 +738,8 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
// buildTransitions as child, the idea being that buildTransitions will // buildTransitions as child, the idea being that buildTransitions will
// animate the entire page into the scene. In the case of _ContextMenuRoute, // animate the entire page into the scene. In the case of _ContextMenuRoute,
// two individual pieces of the page are animated into the scene in // two individual pieces of the page are animated into the scene in
// buildTransitions, and a Container is returned here. // buildTransitions, and a SizedBox.shrink() is returned here.
return Container(); return const SizedBox.shrink();
} }
@override @override
......
...@@ -153,7 +153,7 @@ class _CupertinoDesktopTextSelectionControlsToolbarState extends State<_Cupertin ...@@ -153,7 +153,7 @@ class _CupertinoDesktopTextSelectionControlsToolbarState extends State<_Cupertin
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Don't render the menu until the state of the clipboard is known. // Don't render the menu until the state of the clipboard is known.
if (widget.handlePaste != null && widget.clipboardStatus?.value == ClipboardStatus.unknown) { 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)); assert(debugCheckHasMediaQuery(context));
...@@ -203,7 +203,7 @@ class _CupertinoDesktopTextSelectionControlsToolbarState extends State<_Cupertin ...@@ -203,7 +203,7 @@ class _CupertinoDesktopTextSelectionControlsToolbarState extends State<_Cupertin
// If there is no option available, build an empty widget. // If there is no option available, build an empty widget.
if (items.isEmpty) { if (items.isEmpty) {
return const SizedBox(width: 0.0, height: 0.0); return const SizedBox.shrink();
} }
return _CupertinoDesktopTextSelectionToolbar( return _CupertinoDesktopTextSelectionToolbar(
......
...@@ -1389,7 +1389,7 @@ class _CupertinoAlertContentSection extends StatelessWidget { ...@@ -1389,7 +1389,7 @@ class _CupertinoAlertContentSection extends StatelessWidget {
if (title == null && message == null) { if (title == null && message == null) {
return SingleChildScrollView( return SingleChildScrollView(
controller: scrollController, controller: scrollController,
child: const SizedBox(width: 0.0, height: 0.0), child: const SizedBox.shrink(),
); );
} }
......
...@@ -422,7 +422,7 @@ class CupertinoSliverRefreshControl extends StatefulWidget { ...@@ -422,7 +422,7 @@ class CupertinoSliverRefreshControl extends StatefulWidget {
return CupertinoActivityIndicator(radius: radius * percentageComplete); return CupertinoActivityIndicator(radius: radius * percentageComplete);
case RefreshIndicatorMode.inactive: case RefreshIndicatorMode.inactive:
// Anything else doesn't show anything. // Anything else doesn't show anything.
return Container(); return const SizedBox.shrink();
} }
} }
......
...@@ -504,7 +504,7 @@ class _TabSwitchingViewState extends State<_TabSwitchingView> { ...@@ -504,7 +504,7 @@ class _TabSwitchingViewState extends State<_TabSwitchingView> {
child: FocusScope( child: FocusScope(
node: tabFocusNodes[index], node: tabFocusNodes[index],
child: Builder(builder: (BuildContext context) { child: Builder(builder: (BuildContext context) {
return shouldBuildTab[index] ? widget.tabBuilder(context, index) : Container(); return shouldBuildTab[index] ? widget.tabBuilder(context, index) : const SizedBox.shrink();
}), }),
), ),
), ),
......
...@@ -82,7 +82,7 @@ class _CupertinoTextSelectionControlsToolbarState extends State<_CupertinoTextSe ...@@ -82,7 +82,7 @@ class _CupertinoTextSelectionControlsToolbarState extends State<_CupertinoTextSe
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Don't render the menu until the state of the clipboard is known. // Don't render the menu until the state of the clipboard is known.
if (widget.handlePaste != null && widget.clipboardStatus?.value == ClipboardStatus.unknown) { 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)); assert(debugCheckHasMediaQuery(context));
...@@ -147,7 +147,7 @@ class _CupertinoTextSelectionControlsToolbarState extends State<_CupertinoTextSe ...@@ -147,7 +147,7 @@ class _CupertinoTextSelectionControlsToolbarState extends State<_CupertinoTextSe
// If there is no option available, build an empty widget. // If there is no option available, build an empty widget.
if (items.isEmpty) { if (items.isEmpty) {
return const SizedBox(width: 0.0, height: 0.0); return const SizedBox.shrink();
} }
return CupertinoTextSelectionToolbar( return CupertinoTextSelectionToolbar(
...@@ -266,7 +266,7 @@ class CupertinoTextSelectionControls extends TextSelectionControls { ...@@ -266,7 +266,7 @@ class CupertinoTextSelectionControls extends TextSelectionControls {
); );
// iOS doesn't draw anything for collapsed selections. // iOS doesn't draw anything for collapsed selections.
case TextSelectionHandleType.collapsed: case TextSelectionHandleType.collapsed:
return const SizedBox(); return const SizedBox.shrink();
} }
} }
......
...@@ -1451,7 +1451,7 @@ class _DetailView extends StatelessWidget { ...@@ -1451,7 +1451,7 @@ class _DetailView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_arguments == null) { if (_arguments == null) {
return Container(); return const SizedBox.shrink();
} }
final double screenHeight = MediaQuery.of(context).size.height; final double screenHeight = MediaQuery.of(context).size.height;
final double minHeight = (screenHeight - kToolbarHeight) / screenHeight; final double minHeight = (screenHeight - kToolbarHeight) / screenHeight;
......
...@@ -237,7 +237,7 @@ class DataCell { ...@@ -237,7 +237,7 @@ class DataCell {
}) : assert(child != null); }) : assert(child != null);
/// A cell that has no content and has zero width and height. /// 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. /// The data for the row.
/// ///
......
...@@ -153,7 +153,7 @@ class _DesktopTextSelectionControlsToolbarState extends State<_DesktopTextSelect ...@@ -153,7 +153,7 @@ class _DesktopTextSelectionControlsToolbarState extends State<_DesktopTextSelect
// Don't render the menu until the state of the clipboard is known. // Don't render the menu until the state of the clipboard is known.
if (widget.handlePaste != null && widget.clipboardStatus?.value == ClipboardStatus.unknown) { 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); final MediaQueryData mediaQuery = MediaQuery.of(context);
...@@ -196,7 +196,7 @@ class _DesktopTextSelectionControlsToolbarState extends State<_DesktopTextSelect ...@@ -196,7 +196,7 @@ class _DesktopTextSelectionControlsToolbarState extends State<_DesktopTextSelect
// If there is no option available, build an empty widget. // If there is no option available, build an empty widget.
if (items.isEmpty) { if (items.isEmpty) {
return const SizedBox(width: 0.0, height: 0.0); return const SizedBox.shrink();
} }
return _DesktopTextSelectionToolbar( return _DesktopTextSelectionToolbar(
......
...@@ -1424,7 +1424,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi ...@@ -1424,7 +1424,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
// display the hint or nothing at all. // display the hint or nothing at all.
final Widget innerItemsWidget; final Widget innerItemsWidget;
if (items.isEmpty) { if (items.isEmpty) {
innerItemsWidget = Container(); innerItemsWidget = const SizedBox.shrink();
} else { } else {
innerItemsWidget = IndexedStack( innerItemsWidget = IndexedStack(
index: _selectedIndex ?? hintIndex, index: _selectedIndex ?? hintIndex,
......
...@@ -292,7 +292,7 @@ class _InkState extends State<Ink> { ...@@ -292,7 +292,7 @@ class _InkState extends State<Ink> {
_ink!.decoration = widget.decoration; _ink!.decoration = widget.decoration;
_ink!.configuration = createLocalImageConfiguration(context); _ink!.configuration = createLocalImageConfiguration(context);
} }
return widget.child ?? Container(); return widget.child ?? const SizedBox();
} }
@override @override
......
...@@ -319,7 +319,7 @@ class _HelperError extends StatefulWidget { ...@@ -319,7 +319,7 @@ class _HelperError extends StatefulWidget {
class _HelperErrorState extends State<_HelperError> with SingleTickerProviderStateMixin { class _HelperErrorState extends State<_HelperError> with SingleTickerProviderStateMixin {
// If the height of this widget and the counter are zero ("empty") at // If the height of this widget and the counter are zero ("empty") at
// layout time, no space is allocated for the subtext. // layout time, no space is allocated for the subtext.
static const Widget empty = SizedBox(); static const Widget empty = SizedBox.shrink();
late AnimationController _controller; late AnimationController _controller;
Widget? _helper; Widget? _helper;
......
...@@ -641,7 +641,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin { ...@@ -641,7 +641,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
child: widget.steps[index].label!, child: widget.steps[index].label!,
); );
} }
return const SizedBox(); return const SizedBox.shrink();
} }
Widget _buildVerticalHeader(int index) { Widget _buildVerticalHeader(int index) {
......
...@@ -250,7 +250,7 @@ class _TextSelectionControlsToolbarState extends State<_TextSelectionControlsToo ...@@ -250,7 +250,7 @@ class _TextSelectionControlsToolbarState extends State<_TextSelectionControlsToo
// If there is no option available, build an empty widget. // If there is no option available, build an empty widget.
if (itemDatas.isEmpty) { if (itemDatas.isEmpty) {
return const SizedBox(width: 0.0, height: 0.0); return const SizedBox.shrink();
} }
return TextSelectionToolbar( return TextSelectionToolbar(
......
...@@ -696,7 +696,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin { ...@@ -696,7 +696,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
// the empty black container so just return the wrapped child as is or // the empty black container so just return the wrapped child as is or
// empty container if child is not specified. // empty container if child is not specified.
if (_tooltipMessage.isEmpty) { if (_tooltipMessage.isEmpty) {
return widget.child ?? const SizedBox(); return widget.child ?? const SizedBox.shrink();
} }
assert(debugCheckHasOverlay(context)); assert(debugCheckHasOverlay(context));
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
......
...@@ -3829,10 +3829,10 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -3829,10 +3829,10 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
final int placeholderLocation = _value.text.length - _placeholderLocation; final int placeholderLocation = _value.text.length - _placeholderLocation;
if (_isMultiline) { if (_isMultiline) {
// The zero size placeholder here allows the line to break and keep the caret on the first line. // 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(const _ScribblePlaceholder(child: SizedBox.shrink(), size: Size.zero));
placeholders.add(_ScribblePlaceholder(child: const SizedBox(), size: Size(renderEditable.size.width, 0.0))); placeholders.add(_ScribblePlaceholder(child: const SizedBox.shrink(), size: Size(renderEditable.size.width, 0.0)));
} else { } 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: <InlineSpan>[ return TextSpan(style: widget.style, children: <InlineSpan>[
TextSpan(text: _value.text.substring(0, placeholderLocation)), TextSpan(text: _value.text.substring(0, placeholderLocation)),
......
...@@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart'; ...@@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'basic.dart'; import 'basic.dart';
import 'container.dart';
import 'debug.dart'; import 'debug.dart';
import 'framework.dart'; import 'framework.dart';
...@@ -598,7 +597,7 @@ class _LocalizationsState extends State<Localizations> { ...@@ -598,7 +597,7 @@ class _LocalizationsState extends State<Localizations> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_locale == null) { if (_locale == null) {
return Container(); return const SizedBox.shrink();
} }
return Semantics( return Semantics(
textDirection: _textDirection, textDirection: _textDirection,
......
...@@ -1156,7 +1156,7 @@ class SelectionOverlay { ...@@ -1156,7 +1156,7 @@ class SelectionOverlay {
final Widget handle; final Widget handle;
final TextSelectionControls? selectionControls = this.selectionControls; final TextSelectionControls? selectionControls = this.selectionControls;
if (selectionControls == null) { if (selectionControls == null) {
handle = Container(); handle = const SizedBox.shrink();
} else { } else {
handle = _SelectionHandleOverlay( handle = _SelectionHandleOverlay(
type: _startHandleType, type: _startHandleType,
...@@ -1183,7 +1183,7 @@ class SelectionOverlay { ...@@ -1183,7 +1183,7 @@ class SelectionOverlay {
final TextSelectionControls? selectionControls = this.selectionControls; final TextSelectionControls? selectionControls = this.selectionControls;
if (selectionControls == null || _startHandleType == TextSelectionHandleType.collapsed) { if (selectionControls == null || _startHandleType == TextSelectionHandleType.collapsed) {
// Hide the second handle when collapsed. // Hide the second handle when collapsed.
handle = Container(); handle = const SizedBox.shrink();
} else { } else {
handle = _SelectionHandleOverlay( handle = _SelectionHandleOverlay(
type: _endHandleType, type: _endHandleType,
...@@ -1207,7 +1207,7 @@ class SelectionOverlay { ...@@ -1207,7 +1207,7 @@ class SelectionOverlay {
Widget _buildToolbar(BuildContext context) { Widget _buildToolbar(BuildContext context) {
if (selectionControls == null) { if (selectionControls == null) {
return Container(); return const SizedBox.shrink();
} }
final RenderBox renderBox = this.context.findRenderObject()! as RenderBox; final RenderBox renderBox = this.context.findRenderObject()! as RenderBox;
......
...@@ -9,14 +9,19 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -9,14 +9,19 @@ import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart'; import '../rendering/mock_canvas.dart';
void main() { 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( await tester.pumpWidget(
Material( Material(
child: Ink(), child: Ink(),
), ),
); );
expect(tester.getSize(find.byType(Container)).height, 600.0); Finder sizedBox = find.descendant(
expect(tester.getSize(find.byType(Container)).width, 800.0); 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 height = 150.0;
const double width = 200.0; const double width = 200.0;
...@@ -31,8 +36,13 @@ void main() { ...@@ -31,8 +36,13 @@ void main() {
), ),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(tester.getSize(find.byType(Container)).height, height); sizedBox = find.descendant(
expect(tester.getSize(find.byType(Container)).width, width); 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 { testWidgets('The InkWell widget renders an ink splash', (WidgetTester tester) async {
......
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