From 3193285c7d169e2d7b4b1e787d18fbd5371fe82c Mon Sep 17 00:00:00 2001 From: Pedro Massango Date: Thu, 10 Jun 2021 19:49:40 +0100 Subject: [PATCH] Add SizedBox.square() constructor (#84041) * Add SizedBox.square() constructor * Fix comment and move test case to the right file * Add missing import statement --- packages/flutter/lib/src/widgets/basic.dart | 6 ++++++ packages/flutter/test/widgets/sized_box_test.dart | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index 55b7b3329b..36dba1a34e 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -2250,6 +2250,12 @@ class SizedBox extends SingleChildRenderObjectWidget { height = size?.height, super(key: key, child: child); + /// Creates a box whose [width] and [height] are equal. + const SizedBox.square({Key? key, Widget? child, double? dimension}) + : width = dimension, + height = dimension, + super(key: key, child: child); + /// If non-null, requires the child to have exactly this width. final double? width; diff --git a/packages/flutter/test/widgets/sized_box_test.dart b/packages/flutter/test/widgets/sized_box_test.dart index 71d291a7fe..1ac27b584f 100644 --- a/packages/flutter/test/widgets/sized_box_test.dart +++ b/packages/flutter/test/widgets/sized_box_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -190,4 +191,18 @@ void main() { ); expect(patient.currentContext!.size, equals(Size.zero)); }); + + testWidgets('SizedBox.square tests', (WidgetTester tester) async { + await tester.pumpWidget( + const SizedBox.square( + dimension: 100, + child: SizedBox.shrink(), + ) + ); + + expect( + tester.renderObject(find.byType(SizedBox).first).additionalConstraints, + BoxConstraints.tight(const Size.square(100)), + ); + }); }