Skip to content

Commit 944d2ef

Browse files
author
Hans Muller
authored
Revert "Size of a childless container's implicit DecoratedBox descendants" (flutter#6663)
1 parent abcfc42 commit 944d2ef

File tree

2 files changed

+3
-176
lines changed

2 files changed

+3
-176
lines changed

packages/flutter/lib/src/widgets/container.dart

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,13 @@ class Container extends StatelessWidget {
166166
);
167167
}
168168

169+
if (alignment != null)
170+
current = new Align(alignment: alignment, child: current);
171+
169172
EdgeInsets effectivePadding = _paddingIncludingDecoration;
170173
if (effectivePadding != null)
171174
current = new Padding(padding: effectivePadding, child: current);
172175

173-
// If a child was specified then align it - but not the implicit
174-
// DecoratedBox descendants - within this container.
175-
if (alignment != null && child != null)
176-
current = new Align(alignment: alignment, child: current);
177-
178176
if (decoration != null)
179177
current = new DecoratedBox(decoration: decoration, child: current);
180178

@@ -195,11 +193,6 @@ class Container extends StatelessWidget {
195193
if (transform != null)
196194
current = new Transform(transform: transform, child: current);
197195

198-
// If no child was specified then align the implicit DecoratedBox
199-
// descendants, if any.
200-
if (alignment != null && child == null)
201-
current = new Align(alignment: alignment, child: current);
202-
203196
return current;
204197
}
205198

packages/flutter/test/widget/container_test.dart

Lines changed: 0 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -9,170 +9,4 @@ void main() {
99
testWidgets('Can be placed in an infinite box', (WidgetTester tester) async {
1010
await tester.pumpWidget(new Block(children: <Widget>[new Container()]));
1111
});
12-
13-
testWidgets('Size of a container within an align', (WidgetTester tester) async {
14-
GlobalKey innerContainerKey = new GlobalKey();
15-
16-
await tester.pumpWidget(
17-
new Center(
18-
child: new SizedBox(
19-
width: 300.0,
20-
height: 400.0,
21-
child: new Align(
22-
alignment:FractionalOffset.topLeft,
23-
child: new Container(
24-
key: innerContainerKey,
25-
width: 50.0,
26-
height: 100.0,
27-
),
28-
),
29-
),
30-
),
31-
);
32-
33-
final Size size = innerContainerKey.currentContext.size;
34-
expect(size.width, equals(50.0));
35-
expect(size.height, equals(100.0));
36-
});
37-
38-
testWidgets('Size of an aligned container\'s implicit child', (WidgetTester tester) async {
39-
GlobalKey innerContainerKey = new GlobalKey();
40-
41-
await tester.pumpWidget(
42-
new Center(
43-
child: new SizedBox(
44-
width: 300.0,
45-
height: 400.0,
46-
child: new Container(
47-
key: innerContainerKey,
48-
width: 50.0,
49-
height: 100.0,
50-
alignment:FractionalOffset.topLeft,
51-
decoration: new BoxDecoration(backgroundColor: const Color(0xFF00FF00)),
52-
),
53-
),
54-
),
55-
);
56-
57-
final Size size = innerContainerKey.currentContext.size;
58-
expect(size.width, equals(300.0));
59-
expect(size.height, equals(400.0));
60-
61-
RenderBox box = tester.renderObject(find.byType(DecoratedBox));
62-
expect(box.size.width, equals(50.0));
63-
expect(box.size.height, equals(100.0));
64-
});
65-
66-
testWidgets('Position of an aligned and transformed container\'s implicit child', (WidgetTester tester) async {
67-
GlobalKey innerContainerKey = new GlobalKey();
68-
69-
await tester.pumpWidget(
70-
new Center(
71-
child: new SizedBox(
72-
width: 300.0,
73-
height: 400.0,
74-
child: new Container(
75-
key: innerContainerKey,
76-
width: 50.0,
77-
height: 100.0,
78-
alignment:FractionalOffset.topLeft,
79-
decoration: new BoxDecoration(backgroundColor: const Color(0xFF00FF00)),
80-
transform: new Matrix4.identity()..translate(100.0, 200.0),
81-
),
82-
),
83-
),
84-
);
85-
86-
final Size size = innerContainerKey.currentContext.size;
87-
expect(size.width, equals(300.0));
88-
expect(size.height, equals(400.0));
89-
90-
RenderBox decoratedBox = tester.renderObject(find.byType(DecoratedBox));
91-
expect(decoratedBox.size.width, equals(50.0));
92-
expect(decoratedBox.size.height, equals(100.0));
93-
94-
RenderBox containerBox = innerContainerKey.currentContext.findRenderObject();
95-
Point decoratedBoxOrigin = containerBox.globalToLocal(decoratedBox.localToGlobal(Point.origin));
96-
expect(decoratedBoxOrigin.x, equals(100.0));
97-
expect(decoratedBoxOrigin.y, equals(200.0));
98-
});
99-
100-
testWidgets('Position of an aligned and transformed container\'s implicit children', (WidgetTester tester) async {
101-
GlobalKey innerContainerKey = new GlobalKey();
102-
103-
await tester.pumpWidget(
104-
new Center(
105-
child: new SizedBox(
106-
width: 300.0,
107-
height: 400.0,
108-
child: new Container(
109-
key: innerContainerKey,
110-
width: 50.0,
111-
height: 100.0,
112-
alignment:FractionalOffset.topLeft,
113-
decoration: new BoxDecoration(backgroundColor: const Color(0xFF00FF00)),
114-
foregroundDecoration: new BoxDecoration(backgroundColor: const Color(0xFFFF0000)),
115-
transform: new Matrix4.identity()..translate(100.0, 200.0),
116-
),
117-
),
118-
),
119-
);
120-
121-
final Size size = innerContainerKey.currentContext.size;
122-
expect(size.width, equals(300.0));
123-
expect(size.height, equals(400.0));
124-
125-
RenderBox containerBox = innerContainerKey.currentContext.findRenderObject();
126-
List<RenderObject> renderers = tester.renderObjectList(find.byType(DecoratedBox)).toList();
127-
expect(renderers.length, equals(2));
128-
for (RenderObject renderer in renderers) {
129-
RenderBox decoratedBox = renderer;
130-
expect(decoratedBox.size.width, equals(50.0));
131-
expect(decoratedBox.size.height, equals(100.0));
132-
133-
Point decoratedBoxOrigin = containerBox.globalToLocal(decoratedBox.localToGlobal(Point.origin));
134-
expect(decoratedBoxOrigin.x, equals(100.0));
135-
expect(decoratedBoxOrigin.y, equals(200.0));
136-
}
137-
});
138-
139-
testWidgets('Position of an aligned container\'s implicit children with margins', (WidgetTester tester) async {
140-
GlobalKey innerContainerKey = new GlobalKey();
141-
142-
await tester.pumpWidget(
143-
new Center(
144-
child: new SizedBox(
145-
width: 300.0,
146-
height: 400.0,
147-
child: new Container(
148-
key: innerContainerKey,
149-
width: 50.0,
150-
height: 100.0,
151-
alignment:FractionalOffset.topLeft,
152-
decoration: new BoxDecoration(backgroundColor: const Color(0xFF00FF00)),
153-
foregroundDecoration: new BoxDecoration(backgroundColor: const Color(0xFFFF0000)),
154-
margin: const EdgeInsets.only(left: 25.0, top: 75.0),
155-
),
156-
),
157-
),
158-
);
159-
160-
final Size size = innerContainerKey.currentContext.size;
161-
expect(size.width, equals(300.0));
162-
expect(size.height, equals(400.0));
163-
164-
RenderBox containerBox = innerContainerKey.currentContext.findRenderObject();
165-
List<RenderObject> renderers = tester.renderObjectList(find.byType(DecoratedBox)).toList();
166-
expect(renderers.length, equals(2));
167-
for (RenderObject renderer in renderers) {
168-
RenderBox decoratedBox = renderer;
169-
expect(decoratedBox.size.width, equals(50.0));
170-
expect(decoratedBox.size.height, equals(100.0));
171-
172-
Point decoratedBoxOrigin = containerBox.globalToLocal(decoratedBox.localToGlobal(Point.origin));
173-
expect(decoratedBoxOrigin.x, equals(25.0));
174-
expect(decoratedBoxOrigin.y, equals(75.0));
175-
}
176-
});
177-
17812
}

0 commit comments

Comments
 (0)