Handle empty sizes in AppBar's toolbar layout (#6894)

This commit is contained in:
Jason Simmons
2016-11-16 12:31:56 -08:00
committed by GitHub
parent cac5459401
commit e7c2571b57
2 changed files with 21 additions and 1 deletions

View File

@@ -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;

View File

@@ -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);
});
}