diff --git a/packages/flutter/lib/src/animation/animations.dart b/packages/flutter/lib/src/animation/animations.dart index 234f2815a3..12921f435c 100644 --- a/packages/flutter/lib/src/animation/animations.dart +++ b/packages/flutter/lib/src/animation/animations.dart @@ -395,7 +395,7 @@ class CurvedAnimation extends Animation with AnimationWithParentMixin toolBarRow = []; if (leading != null) { toolBarRow.add(new Padding( @@ -245,20 +276,31 @@ class AppBar extends StatelessWidget { )); } toolBarRow.add(new Flexible( - child: new Padding( - padding: new EdgeInsets.only(left: 8.0), - child: title != null ? - new DefaultTextStyle( - style: centerStyle, - softWrap: false, - overflow: TextOverflow.ellipsis, - child: title - ) : null + child: new Align( + // TODO(abarth): In RTL this should be aligned to the right. + alignment: FractionalOffset.centerLeft, + child: new Padding( + padding: new EdgeInsets.only(left: 8.0), + child: effectiveCenterTitle ? null : centerWidget + ) ) )); if (actions != null) toolBarRow.addAll(actions); + Widget toolBar = new Row(children: toolBarRow); + + if (effectiveCenterTitle && centerWidget != null) { + toolBar = new Stack( + children: [ + // TODO(abarth): If there isn't enough room, we should move the title + // off center rather than overlap the actions. + new Center(child: centerWidget), + toolBar + ] + ); + } + Widget appBar = new SizedBox( height: kToolBarHeight, child: new IconTheme.merge( @@ -266,7 +308,7 @@ class AppBar extends StatelessWidget { data: appBarIconTheme, child: new DefaultTextStyle( style: sideStyle, - child: new Row(children: toolBarRow) + child: toolBar ) ) ); @@ -323,7 +365,7 @@ class AppBar extends StatelessWidget { } appBar = new Material( - color: backgroundColor ?? theme.primaryColor, + color: backgroundColor ?? themeData.primaryColor, elevation: elevation, child: appBar ); diff --git a/packages/flutter/lib/src/material/flexible_space_bar.dart b/packages/flutter/lib/src/material/flexible_space_bar.dart index 8ddcf6b510..a2b77ff08c 100644 --- a/packages/flutter/lib/src/material/flexible_space_bar.dart +++ b/packages/flutter/lib/src/material/flexible_space_bar.dart @@ -83,7 +83,7 @@ class _FlexibleSpaceBarState extends State { case TargetPlatform.iOS: return true; } - return false; + return null; } @override diff --git a/packages/flutter/test/material/app_bar_test.dart b/packages/flutter/test/material/app_bar_test.dart new file mode 100644 index 0000000000..ca798669f0 --- /dev/null +++ b/packages/flutter/test/material/app_bar_test.dart @@ -0,0 +1,45 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('AppBar centers title on iOS', (WidgetTester tester) async { + await tester.pumpWidget( + new MaterialApp( + theme: new ThemeData(platform: TargetPlatform.android), + home: new Scaffold( + appBar: new AppBar( + title: new Text('X') + ) + ) + ) + ); + + Finder title = find.text('X'); + Point center = tester.getCenter(title); + Size size = tester.getSize(title); + expect(center.x, lessThan(400 - size.width / 2.0)); + + // Clear the widget tree to avoid animating between Android and iOS. + await tester.pumpWidget(new Container(key: new UniqueKey())); + + await tester.pumpWidget( + new MaterialApp( + theme: new ThemeData(platform: TargetPlatform.iOS), + home: new Scaffold( + appBar: new AppBar( + title: new Text('X') + ) + ) + ) + ); + + center = tester.getCenter(title); + size = tester.getSize(title); + expect(center.x, greaterThan(400 - size.width / 2.0)); + expect(center.x, lessThan(400 + size.width / 2.0)); + }); +} diff --git a/packages/flutter/test/material/flexible_space_bar_test.dart b/packages/flutter/test/material/flexible_space_bar_test.dart index dd7bc1f282..5f40c6f934 100644 --- a/packages/flutter/test/material/flexible_space_bar_test.dart +++ b/packages/flutter/test/material/flexible_space_bar_test.dart @@ -6,7 +6,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { - testWidgets('Flexible space back centers on iOS', (WidgetTester tester) async { + testWidgets('FlexibleSpaceBar centers title on iOS', (WidgetTester tester) async { await tester.pumpWidget( new MaterialApp( theme: new ThemeData(platform: TargetPlatform.android),