Spacer should only flex in the main axis direction. (#18052)
This commit is contained in:
parent
c7a13e67fd
commit
1891173999
@ -59,8 +59,9 @@ class Spacer extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return new Expanded(
|
||||
flex: flex,
|
||||
child: new ConstrainedBox(
|
||||
constraints: const BoxConstraints.expand(),
|
||||
child: const SizedBox(
|
||||
height: 0.0,
|
||||
width: 0.0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ void main() {
|
||||
],
|
||||
));
|
||||
final Rect spacerRect = tester.getRect(find.byType(Spacer));
|
||||
expect(spacerRect.size, const Size(800.0, 580.0));
|
||||
expect(spacerRect.topLeft, const Offset(0.0, 10.0));
|
||||
expect(spacerRect.size, const Size(0.0, 580.0));
|
||||
expect(spacerRect.topLeft, const Offset(400.0, 10.0));
|
||||
});
|
||||
|
||||
testWidgets('Spacer takes up space proportional to flex.', (WidgetTester tester) async {
|
||||
@ -42,7 +42,7 @@ void main() {
|
||||
final Rect spacer2Rect = tester.getRect(find.byType(Spacer).at(1));
|
||||
final Rect spacer3Rect = tester.getRect(find.byType(Spacer).at(2));
|
||||
final Rect spacer4Rect = tester.getRect(find.byType(Spacer).at(3));
|
||||
expect(spacer1Rect.size.height, 600.0);
|
||||
expect(spacer1Rect.size.height, 0.0);
|
||||
expect(spacer1Rect.size.width, closeTo(93.8, 0.1));
|
||||
expect(spacer1Rect.left, closeTo(696.3, 0.1));
|
||||
expect(spacer2Rect.size.width, closeTo(93.8, 0.1));
|
||||
@ -52,4 +52,22 @@ void main() {
|
||||
expect(spacer4Rect.size.width, spacer3Rect.size.width * 2.0);
|
||||
expect(spacer4Rect.left, closeTo(10.0, 0.1));
|
||||
});
|
||||
|
||||
testWidgets('Spacer takes up space.', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(new UnconstrainedBox(
|
||||
constrainedAxis: Axis.vertical,
|
||||
child: new Column(
|
||||
children: const <Widget>[
|
||||
const SizedBox(width: 20.0, height: 10.0),
|
||||
const Spacer(),
|
||||
const SizedBox(width: 10.0, height: 10.0),
|
||||
],
|
||||
),
|
||||
));
|
||||
final Rect spacerRect = tester.getRect(find.byType(Spacer));
|
||||
final Rect flexRect = tester.getRect(find.byType(Column));
|
||||
expect(spacerRect.size, const Size(0.0, 580.0));
|
||||
expect(spacerRect.topLeft, const Offset(400.0, 10.0));
|
||||
expect(flexRect, new Rect.fromLTWH(390.0, 0.0, 20.0, 600.0));
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user