Add SizedBox.fromSize() constructor (#8144)
This commit is contained in:
parent
f81f1f0509
commit
e09c5cfc66
@ -820,15 +820,24 @@ class CustomMultiChildLayout extends MultiChildRenderObjectWidget {
|
|||||||
/// sizes itself to fit the parent. It is equivalent to setting [width] and
|
/// sizes itself to fit the parent. It is equivalent to setting [width] and
|
||||||
/// [height] to [double.INFINITY].
|
/// [height] to [double.INFINITY].
|
||||||
class SizedBox extends SingleChildRenderObjectWidget {
|
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 })
|
const SizedBox({ Key key, this.width, this.height, Widget child })
|
||||||
: super(key: key, child: 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 })
|
const SizedBox.expand({ Key key, Widget child })
|
||||||
: width = double.INFINITY,
|
: width = double.INFINITY,
|
||||||
height = double.INFINITY,
|
height = double.INFINITY,
|
||||||
super(key: key, child: child);
|
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.
|
/// If non-null, requires the child to have exactly this width.
|
||||||
final double width;
|
final double width;
|
||||||
|
|
||||||
|
@ -6,6 +6,32 @@ import 'package:flutter/widgets.dart';
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
void main() {
|
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 {
|
testWidgets('SizedBox - no child', (WidgetTester tester) async {
|
||||||
GlobalKey patient = new GlobalKey();
|
GlobalKey patient = new GlobalKey();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user