Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
e09c5cfc
Commit
e09c5cfc
authored
Feb 15, 2017
by
Hans Muller
Committed by
GitHub
Feb 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SizedBox.fromSize() constructor (#8144)
parent
f81f1f05
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
1 deletion
+36
-1
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+10
-1
sized_box_test.dart
packages/flutter/test/widgets/sized_box_test.dart
+26
-0
No files found.
packages/flutter/lib/src/widgets/basic.dart
View file @
e09c5cfc
...
...
@@ -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
;
...
...
packages/flutter/test/widgets/sized_box_test.dart
View file @
e09c5cfc
...
...
@@ -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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment