[rename fixit] ToolBar -> AppBar
* left -> leading (Removes an LTR bias) * center -> title (Widget was actually centered) * right -> actions (Removes an LTR bias, asymmetric with leading) Fixes #2348
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
library material;
|
||||
|
||||
export 'src/material/app.dart';
|
||||
export 'src/material/app_bar.dart';
|
||||
export 'src/material/bottom_sheet.dart';
|
||||
export 'src/material/button.dart';
|
||||
export 'src/material/card.dart';
|
||||
@@ -56,7 +57,6 @@ export 'src/material/theme_data.dart';
|
||||
export 'src/material/time_picker.dart';
|
||||
export 'src/material/time_picker_dialog.dart';
|
||||
export 'src/material/toggleable.dart';
|
||||
export 'src/material/tool_bar.dart';
|
||||
export 'src/material/tooltip.dart';
|
||||
export 'src/material/two_level_list.dart';
|
||||
export 'src/material/typography.dart';
|
||||
|
||||
@@ -11,12 +11,12 @@ import 'material.dart';
|
||||
import 'theme.dart';
|
||||
import 'typography.dart';
|
||||
|
||||
class ToolBar extends StatelessWidget {
|
||||
ToolBar({
|
||||
class AppBar extends StatelessWidget {
|
||||
AppBar({
|
||||
Key key,
|
||||
this.left,
|
||||
this.center,
|
||||
this.right,
|
||||
this.leading,
|
||||
this.title,
|
||||
this.actions,
|
||||
this.flexibleSpace,
|
||||
this.foregroundOpacity: 1.0,
|
||||
this.tabBar,
|
||||
@@ -29,9 +29,9 @@ class ToolBar extends StatelessWidget {
|
||||
assert((tabBar != null) ? flexibleSpace == null : true);
|
||||
}
|
||||
|
||||
final Widget left;
|
||||
final Widget center;
|
||||
final List<Widget> right;
|
||||
final Widget leading;
|
||||
final Widget title;
|
||||
final List<Widget> actions;
|
||||
final WidgetBuilder flexibleSpace;
|
||||
final double foregroundOpacity;
|
||||
final Widget tabBar;
|
||||
@@ -40,7 +40,7 @@ class ToolBar extends StatelessWidget {
|
||||
final TextTheme textTheme;
|
||||
final EdgeInsets padding;
|
||||
|
||||
ToolBar copyWith({
|
||||
AppBar copyWith({
|
||||
Key key,
|
||||
Widget left,
|
||||
Widget center,
|
||||
@@ -52,11 +52,11 @@ class ToolBar extends StatelessWidget {
|
||||
TextTheme textTheme,
|
||||
EdgeInsets padding
|
||||
}) {
|
||||
return new ToolBar(
|
||||
return new AppBar(
|
||||
key: key ?? this.key,
|
||||
left: left ?? this.left,
|
||||
center: center ?? this.center,
|
||||
right: right ?? this.right,
|
||||
leading: left ?? this.leading,
|
||||
title: center ?? this.title,
|
||||
actions: right ?? this.actions,
|
||||
flexibleSpace: flexibleSpace ?? this.flexibleSpace,
|
||||
foregroundOpacity: foregroundOpacity ?? this.foregroundOpacity,
|
||||
tabBar: tabBar ?? this.tabBar,
|
||||
@@ -98,18 +98,18 @@ class ToolBar extends StatelessWidget {
|
||||
}
|
||||
|
||||
final List<Widget> toolBarRow = <Widget>[];
|
||||
if (left != null)
|
||||
toolBarRow.add(left);
|
||||
if (leading != null)
|
||||
toolBarRow.add(leading);
|
||||
toolBarRow.add(
|
||||
new Flexible(
|
||||
child: new Padding(
|
||||
padding: new EdgeInsets.only(left: 24.0),
|
||||
child: center != null ? new DefaultTextStyle(style: centerStyle, child: center) : null
|
||||
child: title != null ? new DefaultTextStyle(style: centerStyle, child: title) : null
|
||||
)
|
||||
)
|
||||
);
|
||||
if (right != null)
|
||||
toolBarRow.addAll(right);
|
||||
if (actions != null)
|
||||
toolBarRow.addAll(actions);
|
||||
|
||||
EdgeInsets combinedPadding = new EdgeInsets.symmetric(horizontal: 8.0);
|
||||
if (padding != null)
|
||||
@@ -117,7 +117,7 @@ class ToolBar extends StatelessWidget {
|
||||
|
||||
// If the toolBar's height shrinks below toolBarHeight, it will be clipped and bottom
|
||||
// justified. This is so that the toolbar appears to move upwards as its height is reduced.
|
||||
final double toolBarHeight = kToolBarHeight + combinedPadding.top + combinedPadding.bottom;
|
||||
final double toolBarHeight = kAppBarHeight + combinedPadding.top + combinedPadding.bottom;
|
||||
final Widget toolBar = new ConstrainedBox(
|
||||
constraints: new BoxConstraints(maxHeight: toolBarHeight),
|
||||
child: new Padding(
|
||||
@@ -9,8 +9,8 @@ import 'package:flutter/widgets.dart';
|
||||
// Mobile Landscape: 48dp
|
||||
// Mobile Portrait: 56dp
|
||||
// Tablet/Desktop: 64dp
|
||||
const double kToolBarHeight = 56.0;
|
||||
const double kExtendedToolBarHeight = 128.0;
|
||||
const double kAppBarHeight = 56.0;
|
||||
const double kExtendedAppBarHeight = 128.0;
|
||||
|
||||
const double kTextTabBarHeight = 48.0;
|
||||
const double kIconTabBarHeight = 48.0;
|
||||
|
||||
@@ -27,7 +27,7 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> {
|
||||
final double appBarHeight = Scaffold.of(context).appBarHeight;
|
||||
final Animation<double> animation = Scaffold.of(context).appBarAnimation;
|
||||
final EdgeInsets toolBarPadding = MediaQuery.of(context)?.padding ?? EdgeInsets.zero;
|
||||
final double toolBarHeight = kToolBarHeight + toolBarPadding.top;
|
||||
final double toolBarHeight = kAppBarHeight + toolBarPadding.top;
|
||||
final List<Widget> children = <Widget>[];
|
||||
|
||||
// background image
|
||||
@@ -63,7 +63,7 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> {
|
||||
color: titleStyle.color.withAlpha(new Tween<double>(begin: 255.0, end: 0.0).evaluate(opacityCurve).toInt())
|
||||
);
|
||||
final double yAlignStart = 1.0;
|
||||
final double yAlignEnd = (toolBarPadding.top + kToolBarHeight / 2.0) / toolBarHeight;
|
||||
final double yAlignEnd = (toolBarPadding.top + kAppBarHeight / 2.0) / toolBarHeight;
|
||||
final double scaleAndAlignEnd = (appBarHeight - toolBarHeight) / appBarHeight;
|
||||
final CurvedAnimation scaleAndAlignCurve = new CurvedAnimation(
|
||||
parent: animation,
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'app_bar.dart';
|
||||
import 'bottom_sheet.dart';
|
||||
import 'constants.dart';
|
||||
import 'drawer.dart';
|
||||
@@ -15,7 +16,6 @@ import 'icons.dart';
|
||||
import 'icon_button.dart';
|
||||
import 'material.dart';
|
||||
import 'snack_bar.dart';
|
||||
import 'tool_bar.dart';
|
||||
|
||||
const double _kFloatingActionButtonMargin = 16.0; // TODO(hmuller): should be device dependent
|
||||
const Duration _kFloatingActionButtonSegue = const Duration(milliseconds: 400);
|
||||
@@ -27,7 +27,7 @@ enum AppBarBehavior {
|
||||
|
||||
enum _ScaffoldSlot {
|
||||
body,
|
||||
toolBar,
|
||||
appBar,
|
||||
bottomSheet,
|
||||
snackBar,
|
||||
floatingActionButton,
|
||||
@@ -42,18 +42,18 @@ class _ScaffoldLayout extends MultiChildLayoutDelegate {
|
||||
void performLayout(Size size) {
|
||||
BoxConstraints looseConstraints = new BoxConstraints.loose(size);
|
||||
|
||||
// This part of the layout has the same effect as putting the toolbar and
|
||||
// This part of the layout has the same effect as putting the app bar and
|
||||
// body in a column and making the body flexible. What's different is that
|
||||
// in this case the toolbar appears -after- the body in the stacking order,
|
||||
// so the toolbar's shadow is drawn on top of the body.
|
||||
// in this case the app bar appears -after- the body in the stacking order,
|
||||
// so the app bar's shadow is drawn on top of the body.
|
||||
|
||||
final BoxConstraints fullWidthConstraints = looseConstraints.tighten(width: size.width);
|
||||
double contentTop = padding.top;
|
||||
double contentBottom = size.height - padding.bottom;
|
||||
|
||||
if (hasChild(_ScaffoldSlot.toolBar)) {
|
||||
contentTop = layoutChild(_ScaffoldSlot.toolBar, fullWidthConstraints).height;
|
||||
positionChild(_ScaffoldSlot.toolBar, Offset.zero);
|
||||
if (hasChild(_ScaffoldSlot.appBar)) {
|
||||
contentTop = layoutChild(_ScaffoldSlot.appBar, fullWidthConstraints).height;
|
||||
positionChild(_ScaffoldSlot.appBar, Offset.zero);
|
||||
}
|
||||
|
||||
if (hasChild(_ScaffoldSlot.body)) {
|
||||
@@ -183,7 +183,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
|
||||
class Scaffold extends StatefulWidget {
|
||||
Scaffold({
|
||||
Key key,
|
||||
this.toolBar,
|
||||
this.appBar,
|
||||
this.body,
|
||||
this.floatingActionButton,
|
||||
this.drawer,
|
||||
@@ -192,10 +192,10 @@ class Scaffold extends StatefulWidget {
|
||||
this.appBarHeight
|
||||
}) : super(key: key) {
|
||||
assert((appBarBehavior == AppBarBehavior.scroll) ? scrollableKey != null : true);
|
||||
assert((appBarBehavior == AppBarBehavior.scroll) ? appBarHeight != null && appBarHeight > kToolBarHeight : true);
|
||||
assert((appBarBehavior == AppBarBehavior.scroll) ? appBarHeight != null && appBarHeight > kAppBarHeight : true);
|
||||
}
|
||||
|
||||
final ToolBar toolBar;
|
||||
final AppBar appBar;
|
||||
final Widget body;
|
||||
final Widget floatingActionButton;
|
||||
final Widget drawer;
|
||||
@@ -375,12 +375,12 @@ class ScaffoldState extends State<Scaffold> {
|
||||
|
||||
bool _shouldShowBackArrow;
|
||||
|
||||
Widget _getModifiedToolBar({ EdgeInsets padding, double foregroundOpacity: 1.0, int elevation }) {
|
||||
ToolBar toolBar = config.toolBar;
|
||||
if (toolBar == null)
|
||||
Widget _getModifiedAppBar({ EdgeInsets padding, double foregroundOpacity: 1.0, int elevation }) {
|
||||
AppBar appBar = config.appBar;
|
||||
if (appBar == null)
|
||||
return null;
|
||||
EdgeInsets toolBarPadding = new EdgeInsets.only(top: padding.top);
|
||||
Widget left = toolBar.left;
|
||||
EdgeInsets appBarPadding = new EdgeInsets.only(top: padding.top);
|
||||
Widget left = appBar.leading;
|
||||
if (left == null) {
|
||||
if (config.drawer != null) {
|
||||
left = new IconButton(
|
||||
@@ -399,9 +399,9 @@ class ScaffoldState extends State<Scaffold> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return toolBar.copyWith(
|
||||
elevation: elevation ?? toolBar.elevation ?? 4,
|
||||
padding: toolBarPadding,
|
||||
return appBar.copyWith(
|
||||
elevation: elevation ?? appBar.elevation ?? 4,
|
||||
padding: appBarPadding,
|
||||
foregroundOpacity: foregroundOpacity,
|
||||
left: left
|
||||
);
|
||||
@@ -421,9 +421,9 @@ class ScaffoldState extends State<Scaffold> {
|
||||
return false;
|
||||
}
|
||||
|
||||
double _toolBarOpacity(double progress) {
|
||||
// The value of progress is 1.0 if the entire (padded) toolbar is visible, 0.0
|
||||
// if the toolbar's height is zero.
|
||||
double _appBarOpacity(double progress) {
|
||||
// The value of progress is 1.0 if the entire (padded) app bar is visible, 0.0
|
||||
// if the app bar's height is zero.
|
||||
return new Tween<double>(begin: 0.0, end: 1.0).evaluate(new CurvedAnimation(
|
||||
parent: new AnimationController()..value = progress.clamp(0.0, 1.0),
|
||||
curve: new Interval(0.50, 1.0)
|
||||
@@ -431,35 +431,35 @@ class ScaffoldState extends State<Scaffold> {
|
||||
}
|
||||
|
||||
Widget _buildScrollableAppBar(BuildContext context) {
|
||||
final EdgeInsets toolBarPadding = MediaQuery.of(context)?.padding ?? EdgeInsets.zero;
|
||||
final double toolBarHeight = kToolBarHeight + toolBarPadding.top;
|
||||
final EdgeInsets appBarPadding = MediaQuery.of(context)?.padding ?? EdgeInsets.zero;
|
||||
final double appBarHeight = kAppBarHeight + appBarPadding.top;
|
||||
Widget appBar;
|
||||
|
||||
if (_scrollOffset <= appBarHeight && _scrollOffset >= appBarHeight - toolBarHeight) {
|
||||
// scrolled to the top, only the toolbar is (partially) visible
|
||||
if (_scrollOffset <= appBarHeight && _scrollOffset >= appBarHeight - appBarHeight) {
|
||||
// scrolled to the top, only the app bar is (partially) visible
|
||||
final double height = math.max(_floatingAppBarHeight, appBarHeight - _scrollOffset);
|
||||
final double opacity = _toolBarOpacity(1.0 - ((toolBarHeight - height) / toolBarHeight));
|
||||
final double opacity = _appBarOpacity(1.0 - ((appBarHeight - height) / appBarHeight));
|
||||
_appBarController.value = (appBarHeight - height) / appBarHeight;
|
||||
appBar = new SizedBox(
|
||||
height: height,
|
||||
child: _getModifiedToolBar(padding: toolBarPadding, foregroundOpacity: opacity)
|
||||
child: _getModifiedAppBar(padding: appBarPadding, foregroundOpacity: opacity)
|
||||
);
|
||||
} else if (_scrollOffset > appBarHeight) {
|
||||
// scrolled down, show the "floating" toolbar
|
||||
_floatingAppBarHeight = (_floatingAppBarHeight + _scrollOffsetDelta).clamp(0.0, toolBarHeight);
|
||||
final double toolBarOpacity = _toolBarOpacity(_floatingAppBarHeight / toolBarHeight);
|
||||
// scrolled down, show the "floating" app bar
|
||||
_floatingAppBarHeight = (_floatingAppBarHeight + _scrollOffsetDelta).clamp(0.0, appBarHeight);
|
||||
final double appBarOpacity = _appBarOpacity(_floatingAppBarHeight / appBarHeight);
|
||||
_appBarController.value = (appBarHeight - _floatingAppBarHeight) / appBarHeight;
|
||||
appBar = new SizedBox(
|
||||
height: _floatingAppBarHeight,
|
||||
child: _getModifiedToolBar(padding: toolBarPadding, foregroundOpacity: toolBarOpacity)
|
||||
child: _getModifiedAppBar(padding: appBarPadding, foregroundOpacity: appBarOpacity)
|
||||
);
|
||||
} else {
|
||||
// _scrollOffset < appBarHeight - toolBarHeight, scrolled to the top, flexible space is visible
|
||||
// _scrollOffset < appBarHeight - appBarHeight, scrolled to the top, flexible space is visible
|
||||
final double height = appBarHeight - _scrollOffset.clamp(0.0, appBarHeight);
|
||||
_appBarController.value = (appBarHeight - height) / appBarHeight;
|
||||
appBar = new SizedBox(
|
||||
height: height,
|
||||
child: _getModifiedToolBar(padding: toolBarPadding, elevation: 0)
|
||||
child: _getModifiedAppBar(padding: appBarPadding, elevation: 0)
|
||||
);
|
||||
_floatingAppBarHeight = 0.0;
|
||||
}
|
||||
@@ -484,13 +484,13 @@ class ScaffoldState extends State<Scaffold> {
|
||||
final List<LayoutId> children = new List<LayoutId>();
|
||||
_addIfNonNull(children, config.body, _ScaffoldSlot.body);
|
||||
if (config.appBarBehavior == AppBarBehavior.anchor) {
|
||||
Widget toolBar = new ConstrainedBox(
|
||||
child: _getModifiedToolBar(padding: padding),
|
||||
constraints: new BoxConstraints(maxHeight: config.appBarHeight ?? kExtendedToolBarHeight + padding.top)
|
||||
Widget appBar = new ConstrainedBox(
|
||||
child: _getModifiedAppBar(padding: padding),
|
||||
constraints: new BoxConstraints(maxHeight: config.appBarHeight ?? kExtendedAppBarHeight + padding.top)
|
||||
);
|
||||
_addIfNonNull(children, toolBar, _ScaffoldSlot.toolBar);
|
||||
_addIfNonNull(children, appBar, _ScaffoldSlot.appBar);
|
||||
}
|
||||
// Otherwise the ToolBar will be part of a [toolbar, body] Stack. See AppBarBehavior.scroll below.
|
||||
// Otherwise the AppBar will be part of a [app bar, body] Stack. See AppBarBehavior.scroll below.
|
||||
|
||||
if (_currentBottomSheet != null ||
|
||||
(_dismissedBottomSheets != null && _dismissedBottomSheets.isNotEmpty)) {
|
||||
|
||||
@@ -31,7 +31,7 @@ void main() {
|
||||
title: "Markdown Demo",
|
||||
routes: <String, WidgetBuilder>{
|
||||
'/': (BuildContext context) => new Scaffold(
|
||||
toolBar: new ToolBar(center: new Text("Markdown Demo")),
|
||||
appBar: new AppBar(title: new Text("Markdown Demo")),
|
||||
body: new Markdown(data: _kMarkdownData)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ class _FlutterDemoState extends State<FlutterDemo> {
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
toolBar: new ToolBar(
|
||||
center: new Text('Flutter Demo')
|
||||
appBar: new AppBar(
|
||||
title: new Text('Flutter Demo')
|
||||
),
|
||||
body: new Center(
|
||||
child: new Text('Button tapped $_counter time${ _counter == 1 ? '' : 's' }.')
|
||||
|
||||
Reference in New Issue
Block a user