mirror of
https://github.com/flutter/flutter
synced 2024-10-13 03:32:55 +00:00
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:
parent
02b46b0d77
commit
3193285c7d
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue