diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index 8127b2abdb..b1c7082790 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:math' as math; + import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; @@ -58,7 +60,7 @@ class _ToolbarLayout extends MultiChildLayoutDelegate { } if (hasChild(_ToolbarSlot.title)) { - final double maxWidth = size.width - kTitleLeft - actionsWidth; + final double maxWidth = math.max(size.width - kTitleLeft - actionsWidth, 0.0); final BoxConstraints constraints = new BoxConstraints.loose(size).copyWith(maxWidth: maxWidth); final Size titleSize = layoutChild(_ToolbarSlot.title, constraints); final double titleY = (size.height - titleSize.height) / 2.0; diff --git a/packages/flutter/test/material/app_bar_test.dart b/packages/flutter/test/material/app_bar_test.dart index bcbd461ff3..263ff0dee8 100644 --- a/packages/flutter/test/material/app_bar_test.dart +++ b/packages/flutter/test/material/app_bar_test.dart @@ -179,4 +179,22 @@ void main() { expect(tester.getSize(title).width, equals(620.0)); }); + testWidgets('AppBar render at zero size', (WidgetTester tester) async { + await tester.pumpWidget( + new Center( + child: new Container( + height: 0.0, + width: 0.0, + child: new Scaffold( + appBar: new AppBar( + title: new Text('X') + ) + ) + ) + ) + ); + + Finder title = find.text('X'); + expect(tester.getSize(title).isEmpty, isTrue); + }); }