Automatically fill in the menu button when there's a drawer

Also, fill in a back arrow when we can go back.

Fixes #699
This commit is contained in:
Adam Barth
2015-12-03 16:18:12 -08:00
parent 5ad32f2987
commit e17c3eccf6
11 changed files with 56 additions and 53 deletions

View File

@@ -16,6 +16,7 @@ import 'material.dart';
import 'snack_bar.dart';
import 'tool_bar.dart';
import 'drawer.dart';
import 'icon_button.dart';
const double _kFloatingActionButtonMargin = 16.0; // TODO(hmuller): should be device dependent
@@ -257,8 +258,37 @@ class ScaffoldState extends State<Scaffold> {
children.add(new LayoutId(child: child, id: childId));
}
bool _shouldShowBackArrow;
Widget get _modifiedToolBar {
ToolBar toolBar = config.toolBar;
if (toolBar == null)
return null;
EdgeDims padding = new EdgeDims.only(top: ui.window.padding.top);
Widget left = toolBar.left;
if (left == null) {
if (config.drawer != null) {
left = new IconButton(
icon: 'navigation/menu',
onPressed: openDrawer
);
} else {
_shouldShowBackArrow ??= Navigator.canPop(context);
if (_shouldShowBackArrow) {
left = new IconButton(
icon: 'navigation/arrow_back',
onPressed: () => Navigator.pop(context)
);
}
}
}
return toolBar.copyWith(
padding: padding,
left: left
);
}
Widget build(BuildContext context) {
final Widget paddedToolBar = config.toolBar?.withPadding(new EdgeDims.only(top: ui.window.padding.top));
final Widget materialBody = config.body != null ? new Material(child: config.body) : null;
if (_snackBars.length > 0) {
@@ -274,7 +304,7 @@ class ScaffoldState extends State<Scaffold> {
final List<LayoutId>children = new List<LayoutId>();
_addIfNonNull(children, materialBody, _Child.body);
_addIfNonNull(children, paddedToolBar, _Child.toolBar);
_addIfNonNull(children, _modifiedToolBar, _Child.toolBar);
if (_currentBottomSheet != null ||
(_dismissedBottomSheets != null && _dismissedBottomSheets.isNotEmpty)) {

View File

@@ -36,18 +36,28 @@ class ToolBar extends StatelessComponent {
final TextTheme textTheme;
final EdgeDims padding;
ToolBar withPadding(EdgeDims newPadding, { Key fallbackKey }) {
ToolBar copyWith({
Key key,
Widget left,
Widget center,
List<Widget> right,
Widget bottom,
int elevation,
Color backgroundColor,
TextTheme textTheme,
EdgeDims padding
}) {
return new ToolBar(
key: key ?? fallbackKey,
left: left,
center: center,
right: right,
bottom: bottom,
tabBar: tabBar,
elevation: elevation,
backgroundColor: backgroundColor,
textTheme: textTheme,
padding: newPadding
key: key ?? this.key,
left: left ?? this.left,
center: center ?? this.center,
right: right ?? this.right,
bottom: bottom ?? this.bottom,
tabBar: tabBar ?? this.tabBar,
elevation: elevation ?? this.elevation,
backgroundColor: backgroundColor ?? this.backgroundColor,
textTheme: textTheme ?? this.textTheme,
padding: padding ?? this.padding
);
}