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
6f3ba9c5
Commit
6f3ba9c5
authored
Nov 02, 2016
by
Hans Muller
Committed by
GitHub
Nov 02, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Size of a childless container's implicit DecoratedBox descendants (#6656)
parent
5097fd4f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
176 additions
and
3 deletions
+176
-3
container.dart
packages/flutter/lib/src/widgets/container.dart
+10
-3
container_test.dart
packages/flutter/test/widget/container_test.dart
+166
-0
No files found.
packages/flutter/lib/src/widgets/container.dart
View file @
6f3ba9c5
...
...
@@ -166,13 +166,15 @@ class Container extends StatelessWidget {
);
}
if
(
alignment
!=
null
)
current
=
new
Align
(
alignment:
alignment
,
child:
current
);
EdgeInsets
effectivePadding
=
_paddingIncludingDecoration
;
if
(
effectivePadding
!=
null
)
current
=
new
Padding
(
padding:
effectivePadding
,
child:
current
);
// If a child was specified then align it - but not the implicit
// DecoratedBox descendants - within this container.
if
(
alignment
!=
null
&&
child
!=
null
)
current
=
new
Align
(
alignment:
alignment
,
child:
current
);
if
(
decoration
!=
null
)
current
=
new
DecoratedBox
(
decoration:
decoration
,
child:
current
);
...
...
@@ -193,6 +195,11 @@ class Container extends StatelessWidget {
if
(
transform
!=
null
)
current
=
new
Transform
(
transform:
transform
,
child:
current
);
// If no child was specified then align the implicit DecoratedBox
// descendants, if any.
if
(
alignment
!=
null
&&
child
==
null
)
current
=
new
Align
(
alignment:
alignment
,
child:
current
);
return
current
;
}
...
...
packages/flutter/test/widget/container_test.dart
View file @
6f3ba9c5
...
...
@@ -9,4 +9,170 @@ void main() {
testWidgets
(
'Can be placed in an infinite box'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
Block
(
children:
<
Widget
>[
new
Container
()]));
});
testWidgets
(
'Size of a container within an align'
,
(
WidgetTester
tester
)
async
{
GlobalKey
innerContainerKey
=
new
GlobalKey
();
await
tester
.
pumpWidget
(
new
Center
(
child:
new
SizedBox
(
width:
300.0
,
height:
400.0
,
child:
new
Align
(
alignment:
FractionalOffset
.
topLeft
,
child:
new
Container
(
key:
innerContainerKey
,
width:
50.0
,
height:
100.0
,
),
),
),
),
);
final
Size
size
=
innerContainerKey
.
currentContext
.
size
;
expect
(
size
.
width
,
equals
(
50.0
));
expect
(
size
.
height
,
equals
(
100.0
));
});
testWidgets
(
'Size of an aligned container
\'
s implicit child'
,
(
WidgetTester
tester
)
async
{
GlobalKey
innerContainerKey
=
new
GlobalKey
();
await
tester
.
pumpWidget
(
new
Center
(
child:
new
SizedBox
(
width:
300.0
,
height:
400.0
,
child:
new
Container
(
key:
innerContainerKey
,
width:
50.0
,
height:
100.0
,
alignment:
FractionalOffset
.
topLeft
,
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF00FF00
)),
),
),
),
);
final
Size
size
=
innerContainerKey
.
currentContext
.
size
;
expect
(
size
.
width
,
equals
(
300.0
));
expect
(
size
.
height
,
equals
(
400.0
));
RenderBox
box
=
tester
.
renderObject
(
find
.
byType
(
DecoratedBox
));
expect
(
box
.
size
.
width
,
equals
(
50.0
));
expect
(
box
.
size
.
height
,
equals
(
100.0
));
});
testWidgets
(
'Position of an aligned and transformed container
\'
s implicit child'
,
(
WidgetTester
tester
)
async
{
GlobalKey
innerContainerKey
=
new
GlobalKey
();
await
tester
.
pumpWidget
(
new
Center
(
child:
new
SizedBox
(
width:
300.0
,
height:
400.0
,
child:
new
Container
(
key:
innerContainerKey
,
width:
50.0
,
height:
100.0
,
alignment:
FractionalOffset
.
topLeft
,
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF00FF00
)),
transform:
new
Matrix4
.
identity
()..
translate
(
100.0
,
200.0
),
),
),
),
);
final
Size
size
=
innerContainerKey
.
currentContext
.
size
;
expect
(
size
.
width
,
equals
(
300.0
));
expect
(
size
.
height
,
equals
(
400.0
));
RenderBox
decoratedBox
=
tester
.
renderObject
(
find
.
byType
(
DecoratedBox
));
expect
(
decoratedBox
.
size
.
width
,
equals
(
50.0
));
expect
(
decoratedBox
.
size
.
height
,
equals
(
100.0
));
RenderBox
containerBox
=
innerContainerKey
.
currentContext
.
findRenderObject
();
Point
decoratedBoxOrigin
=
containerBox
.
globalToLocal
(
decoratedBox
.
localToGlobal
(
Point
.
origin
));
expect
(
decoratedBoxOrigin
.
x
,
equals
(
100.0
));
expect
(
decoratedBoxOrigin
.
y
,
equals
(
200.0
));
});
testWidgets
(
'Position of an aligned and transformed container
\'
s implicit children'
,
(
WidgetTester
tester
)
async
{
GlobalKey
innerContainerKey
=
new
GlobalKey
();
await
tester
.
pumpWidget
(
new
Center
(
child:
new
SizedBox
(
width:
300.0
,
height:
400.0
,
child:
new
Container
(
key:
innerContainerKey
,
width:
50.0
,
height:
100.0
,
alignment:
FractionalOffset
.
topLeft
,
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF00FF00
)),
foregroundDecoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFFFF0000
)),
transform:
new
Matrix4
.
identity
()..
translate
(
100.0
,
200.0
),
),
),
),
);
final
Size
size
=
innerContainerKey
.
currentContext
.
size
;
expect
(
size
.
width
,
equals
(
300.0
));
expect
(
size
.
height
,
equals
(
400.0
));
RenderBox
containerBox
=
innerContainerKey
.
currentContext
.
findRenderObject
();
List
<
RenderObject
>
renderers
=
tester
.
renderObjectList
(
find
.
byType
(
DecoratedBox
)).
toList
();
expect
(
renderers
.
length
,
equals
(
2
));
for
(
RenderObject
renderer
in
renderers
)
{
RenderBox
decoratedBox
=
renderer
;
expect
(
decoratedBox
.
size
.
width
,
equals
(
50.0
));
expect
(
decoratedBox
.
size
.
height
,
equals
(
100.0
));
Point
decoratedBoxOrigin
=
containerBox
.
globalToLocal
(
decoratedBox
.
localToGlobal
(
Point
.
origin
));
expect
(
decoratedBoxOrigin
.
x
,
equals
(
100.0
));
expect
(
decoratedBoxOrigin
.
y
,
equals
(
200.0
));
}
});
testWidgets
(
'Position of an aligned container
\'
s implicit children with margins'
,
(
WidgetTester
tester
)
async
{
GlobalKey
innerContainerKey
=
new
GlobalKey
();
await
tester
.
pumpWidget
(
new
Center
(
child:
new
SizedBox
(
width:
300.0
,
height:
400.0
,
child:
new
Container
(
key:
innerContainerKey
,
width:
50.0
,
height:
100.0
,
alignment:
FractionalOffset
.
topLeft
,
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF00FF00
)),
foregroundDecoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFFFF0000
)),
margin:
const
EdgeInsets
.
only
(
left:
25.0
,
top:
75.0
),
),
),
),
);
final
Size
size
=
innerContainerKey
.
currentContext
.
size
;
expect
(
size
.
width
,
equals
(
300.0
));
expect
(
size
.
height
,
equals
(
400.0
));
RenderBox
containerBox
=
innerContainerKey
.
currentContext
.
findRenderObject
();
List
<
RenderObject
>
renderers
=
tester
.
renderObjectList
(
find
.
byType
(
DecoratedBox
)).
toList
();
expect
(
renderers
.
length
,
equals
(
2
));
for
(
RenderObject
renderer
in
renderers
)
{
RenderBox
decoratedBox
=
renderer
;
expect
(
decoratedBox
.
size
.
width
,
equals
(
50.0
));
expect
(
decoratedBox
.
size
.
height
,
equals
(
100.0
));
Point
decoratedBoxOrigin
=
containerBox
.
globalToLocal
(
decoratedBox
.
localToGlobal
(
Point
.
origin
));
expect
(
decoratedBoxOrigin
.
x
,
equals
(
25.0
));
expect
(
decoratedBoxOrigin
.
y
,
equals
(
75.0
));
}
});
}
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