Add SizedBox.square() constructor (#84041)

* Add SizedBox.square() constructor

* Fix comment and move test case to the right file

* Add missing import statement
This commit is contained in:
Pedro Massango 2021-06-10 19:49:40 +01:00 committed by GitHub
parent 02b46b0d77
commit 3193285c7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -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;

View file

@ -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<RenderConstrainedBox>(find.byType(SizedBox).first).additionalConstraints,
BoxConstraints.tight(const Size.square(100)),
);
});
}