Unverified Commit 3193285c authored by Pedro Massango's avatar Pedro Massango Committed by GitHub

Add SizedBox.square() constructor (#84041)

* Add SizedBox.square() constructor

* Fix comment and move test case to the right file

* Add missing import statement
parent 02b46b0d
...@@ -2250,6 +2250,12 @@ class SizedBox extends SingleChildRenderObjectWidget { ...@@ -2250,6 +2250,12 @@ class SizedBox extends SingleChildRenderObjectWidget {
height = size?.height, height = size?.height,
super(key: key, child: child); 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. /// If non-null, requires the child to have exactly this width.
final double? width; final double? width;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -190,4 +191,18 @@ void main() { ...@@ -190,4 +191,18 @@ void main() {
); );
expect(patient.currentContext!.size, equals(Size.zero)); 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<RenderConstrainedBox>(find.byType(SizedBox).first).additionalConstraints,
BoxConstraints.tight(const Size.square(100)),
);
});
} }
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