From b40f0cae9c279c688c6491d69426709da6f136d4 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 6 Jan 2017 13:59:40 -0800 Subject: [PATCH] Allow Expanded.flex to be null (#7384) Some clients pass null, which was previously allowed by Flexible. Fixes #7383 --- packages/flutter/lib/src/widgets/basic.dart | 4 +- packages/flutter/test/widgets/flex_test.dart | 39 +++++++++++++------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index 6ebc8769b6..7939ba6243 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -2308,9 +2308,7 @@ class Expanded extends Flexible { Key key, int flex: 1, @required Widget child, - }) : super(key: key, flex: flex, fit: FlexFit.tight, child: child) { - assert(flex > 0); - } + }) : super(key: key, flex: flex, fit: FlexFit.tight, child: child); } /// A widget that implements the flow layout algorithm. diff --git a/packages/flutter/test/widgets/flex_test.dart b/packages/flutter/test/widgets/flex_test.dart index 388d192ad1..02d5444f4d 100644 --- a/packages/flutter/test/widgets/flex_test.dart +++ b/packages/flutter/test/widgets/flex_test.dart @@ -7,12 +7,13 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; void main() { - testWidgets('Can hit test flex children of stacks', (WidgetTester tester) async { + testWidgets('Can hit test flex children of stacks', + (WidgetTester tester) async { bool didReceiveTap = false; await tester.pumpWidget( new Container( decoration: const BoxDecoration( - backgroundColor: const Color(0xFF00FF00) + backgroundColor: const Color(0xFF00FF00), ), child: new Stack( children: [ @@ -27,24 +28,34 @@ void main() { }, child: new Container( decoration: const BoxDecoration( - backgroundColor: const Color(0xFF0000FF) - ), + backgroundColor: const Color(0xFF0000FF)), width: 100.0, height: 100.0, child: new Center( - child: new Text('X') - ) - ) - ) - ] - ) - ) - ] - ) - ) + child: new Text('X'), + ), + ), + ), + ], + ), + ), + ], + ), + ), ); await tester.tap(find.text('X')); expect(didReceiveTap, isTrue); }); + + testWidgets('Can pass null for flex', (WidgetTester tester) async { + await tester.pumpWidget( + new Row( + children: [ + new Expanded(flex: null, child: new Text('one')), + new Flexible(flex: null, child: new Text('two')), + ], + ), + ); + }); }