Commit e09c5cfc authored by Hans Muller's avatar Hans Muller Committed by GitHub

Add SizedBox.fromSize() constructor (#8144)

parent f81f1f05
......@@ -820,15 +820,24 @@ class CustomMultiChildLayout extends MultiChildRenderObjectWidget {
/// sizes itself to fit the parent. It is equivalent to setting [width] and
/// [height] to [double.INFINITY].
class SizedBox extends SingleChildRenderObjectWidget {
/// Creates a box of a specific size.
/// Creates a fixed size box. The [width] and [height] parameters can be null
/// to indicate that the size of the box should not be constrained in
/// the corresponding dimension.
const SizedBox({ Key key, this.width, this.height, Widget child })
: super(key: key, child: child);
/// Creates a box that will become as large as its parent allows.
const SizedBox.expand({ Key key, Widget child })
: width = double.INFINITY,
height = double.INFINITY,
super(key: key, child: child);
/// Creates a box with the specified size.
SizedBox.fromSize({ Key key, Widget child, Size size })
: width = size?.width,
height = size?.height,
super(key: key, child: child);
/// If non-null, requires the child to have exactly this width.
final double width;
......
......@@ -6,6 +6,32 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('SizedBox constructors', (WidgetTester tester) async {
final SizedBox a = const SizedBox();
expect(a.width, isNull);
expect(a.height, isNull);
final SizedBox b = const SizedBox(width: 10.0);
expect(b.width, 10.0);
expect(b.height, isNull);
final SizedBox c = const SizedBox(width: 10.0, height: 20.0);
expect(c.width, 10.0);
expect(c.height, 20.0);
final SizedBox d = new SizedBox.fromSize();
expect(d.width, isNull);
expect(d.height, isNull);
final SizedBox e = new SizedBox.fromSize(size: const Size(1.0, 2.0));
expect(e.width, 1.0);
expect(e.height, 2.0);
final SizedBox f = const SizedBox.expand();
expect(f.width, double.INFINITY);
expect(f.height, double.INFINITY);
});
testWidgets('SizedBox - no child', (WidgetTester tester) async {
GlobalKey patient = new GlobalKey();
......
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