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> {
// 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
......
......@@ -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(
......
......@@ -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(),
);
}
......
......@@ -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();
}
}
......
......@@ -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();
}),
),
),
......
......@@ -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();
}
}
......
......@@ -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;
......
......@@ -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.
///
......
......@@ -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(
......
......@@ -1424,7 +1424,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> 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,
......
......@@ -292,7 +292,7 @@ class _InkState extends State<Ink> {
_ink!.decoration = widget.decoration;
_ink!.configuration = createLocalImageConfiguration(context);
}
return widget.child ?? Container();
return widget.child ?? const SizedBox();
}
@override
......
......@@ -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;
......
......@@ -641,7 +641,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
child: widget.steps[index].label!,
);
}
return const SizedBox();
return const SizedBox.shrink();
}
Widget _buildVerticalHeader(int index) {
......
......@@ -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(
......
......@@ -696,7 +696,7 @@ class TooltipState extends State<Tooltip> 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);
......
......@@ -3829,10 +3829,10 @@ class EditableTextState extends State<EditableText> 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: <InlineSpan>[
TextSpan(text: _value.text.substring(0, placeholderLocation)),
......
......@@ -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<Localizations> {
@override
Widget build(BuildContext context) {
if (_locale == null) {
return Container();
return const SizedBox.shrink();
}
return Semantics(
textDirection: _textDirection,
......
......@@ -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;
......
......@@ -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 {
......
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