From 18911739996d47b0ebbddbea515ae6c25f48918a Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Thu, 31 May 2018 20:38:37 -0700 Subject: [PATCH] Spacer should only flex in the main axis direction. (#18052) --- packages/flutter/lib/src/widgets/spacer.dart | 5 ++-- .../flutter/test/widgets/spacer_test.dart | 24 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/flutter/lib/src/widgets/spacer.dart b/packages/flutter/lib/src/widgets/spacer.dart index 3df7dd991a..af4da9a0da 100644 --- a/packages/flutter/lib/src/widgets/spacer.dart +++ b/packages/flutter/lib/src/widgets/spacer.dart @@ -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, ), ); } diff --git a/packages/flutter/test/widgets/spacer_test.dart b/packages/flutter/test/widgets/spacer_test.dart index b9c0ed0d36..2c0e010444 100644 --- a/packages/flutter/test/widgets/spacer_test.dart +++ b/packages/flutter/test/widgets/spacer_test.dart @@ -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 [ + 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)); + }); }