Commit fe3aee88 authored by Hans Muller's avatar Hans Muller

added ToolBar.withSizeOffsets()

parent 1b578e9e
...@@ -268,15 +268,14 @@ class CardCollectionState extends State<CardCollection> { ...@@ -268,15 +268,14 @@ class CardCollectionState extends State<CardCollection> {
Widget buildToolBar() { Widget buildToolBar() {
return new ToolBar( return new ToolBar(
left: new IconButton(icon: "navigation/menu", onPressed: _showDrawer), left: new IconButton(icon: "navigation/menu", onPressed: _showDrawer),
center: new Text('Swipe Away'),
right: <Widget>[ right: <Widget>[
new Text(_dismissDirectionText(_dismissDirection)) new Text(_dismissDirectionText(_dismissDirection))
], ],
bottom: new Padding( bottom: new Padding(
padding: const EdgeDims.only(left: 32.0), padding: const EdgeDims.only(left: 72.0),
child: new Align( child: new Align(
alignment: const FractionalOffset(0.0, 0.5), alignment: const FractionalOffset(0.0, 0.5),
child: new Text("Remaining items: ${_cardModels.length}") child: new Text('Swipe Away: ${_cardModels.length}')
) )
) )
); );
......
...@@ -218,18 +218,18 @@ class DropdownButton<T> extends StatelessComponent { ...@@ -218,18 +218,18 @@ class DropdownButton<T> extends StatelessComponent {
return new GestureDetector( return new GestureDetector(
child: new Container( child: new Container(
decoration: new BoxDecoration(border: _kDropdownUnderline), decoration: new BoxDecoration(border: _kDropdownUnderline),
child: new IntrinsicWidth( child: new Row(<Widget>[
child: new Row(<Widget>[ new IndexedStack(items,
new IndexedStack(items, key: indexedStackKey,
key: indexedStackKey, index: selectedIndex,
index: selectedIndex, alignment: const FractionalOffset(0.5, 0.0)
alignment: const FractionalOffset(0.5, 0.0) ),
), new Container(
new Container( child: new Icon(icon: 'navigation/arrow_drop_down', size: IconSize.s36),
child: new Icon(icon: 'navigation/arrow_drop_down', size: IconSize.s36), padding: const EdgeDims.only(top: 6.0)
padding: const EdgeDims.only(top: 6.0) )
) ],
]) justifyContent: FlexJustifyContent.collapse
) )
), ),
onTap: () { onTap: () {
......
...@@ -10,8 +10,8 @@ import 'package:flutter/widgets.dart'; ...@@ -10,8 +10,8 @@ import 'package:flutter/widgets.dart';
import 'constants.dart'; import 'constants.dart';
import 'material.dart'; import 'material.dart';
const int _kToolBarIndex = 1;
const int _kBodyIndex = 0; const int _kBodyIndex = 0;
const int _kToolBarIndex = 1;
// This layout has the same effect as putting the toolbar and body in a column // This layout has the same effect as putting the toolbar and body in a column
// and making the body flexible. What's different is that in this case the // and making the body flexible. What's different is that in this case the
...@@ -22,18 +22,17 @@ class _ToolBarAndBodyLayout extends MultiChildLayoutDelegate { ...@@ -22,18 +22,17 @@ class _ToolBarAndBodyLayout extends MultiChildLayoutDelegate {
assert(childCount == 2); assert(childCount == 2);
final BoxConstraints toolBarConstraints = constraints.loosen().tightenWidth(size.width); final BoxConstraints toolBarConstraints = constraints.loosen().tightenWidth(size.width);
final Size toolBarSize = layoutChild(_kToolBarIndex, toolBarConstraints); final Size toolBarSize = layoutChild(_kToolBarIndex, toolBarConstraints);
final double topPadding = ui.window.padding.top; final double bodyHeight = size.height - toolBarSize.height;
final double bodyHeight = size.height - toolBarSize.height - topPadding;
final BoxConstraints bodyConstraints = toolBarConstraints.tightenHeight(bodyHeight); final BoxConstraints bodyConstraints = toolBarConstraints.tightenHeight(bodyHeight);
layoutChild(_kBodyIndex, bodyConstraints); layoutChild(_kBodyIndex, bodyConstraints);
positionChild(_kToolBarIndex, new Point(0.0, topPadding)); positionChild(_kToolBarIndex, Point.origin);
positionChild(_kBodyIndex, new Point(0.0, topPadding + toolBarSize.height)); positionChild(_kBodyIndex, new Point(0.0, toolBarSize.height));
} }
} }
class Scaffold extends StatelessComponent { final _ToolBarAndBodyLayout _toolBarAndBodyLayout = new _ToolBarAndBodyLayout();
final _ToolBarAndBodyLayout _toolBarAndBodyLayout = new _ToolBarAndBodyLayout();
class Scaffold extends StatelessComponent {
Scaffold({ Scaffold({
Key key, Key key,
this.body, this.body,
...@@ -48,14 +47,15 @@ class Scaffold extends StatelessComponent { ...@@ -48,14 +47,15 @@ class Scaffold extends StatelessComponent {
final Widget floatingActionButton; final Widget floatingActionButton;
Widget build(BuildContext context) { Widget build(BuildContext context) {
final offsetToolBar = toolBar?.withSizeOffsets(new EdgeDims.only(top: ui.window.padding.top));
final Widget materialBody = body != null ? new Material(child: body) : null; final Widget materialBody = body != null ? new Material(child: body) : null;
Widget toolBarAndBody; Widget toolBarAndBody;
if (toolBar != null && materialBody != null) if (offsetToolBar != null && materialBody != null)
toolBarAndBody = new CustomMultiChildLayout(<Widget>[materialBody, toolBar], toolBarAndBody = new CustomMultiChildLayout(<Widget>[materialBody, offsetToolBar],
delegate: _toolBarAndBodyLayout delegate: _toolBarAndBodyLayout
); );
else else
toolBarAndBody = toolBar ?? materialBody; toolBarAndBody = offsetToolBar ?? materialBody;
final List<Widget> bottomColumnChildren = <Widget>[]; final List<Widget> bottomColumnChildren = <Widget>[];
......
...@@ -20,7 +20,8 @@ class ToolBar extends StatelessComponent { ...@@ -20,7 +20,8 @@ class ToolBar extends StatelessComponent {
this.bottom, this.bottom,
this.level: 2, this.level: 2,
this.backgroundColor, this.backgroundColor,
this.textTheme this.textTheme,
this.sizeOffsets: EdgeDims.zero
}) : super(key: key); }) : super(key: key);
final Widget left; final Widget left;
...@@ -30,6 +31,21 @@ class ToolBar extends StatelessComponent { ...@@ -30,6 +31,21 @@ class ToolBar extends StatelessComponent {
final int level; final int level;
final Color backgroundColor; final Color backgroundColor;
final TextTheme textTheme; final TextTheme textTheme;
final EdgeDims sizeOffsets;
ToolBar withSizeOffsets(EdgeDims offsets) {
return new ToolBar(
key: key,
left: left,
center: center,
right: right,
bottom: bottom,
level: level,
backgroundColor: backgroundColor,
textTheme: textTheme,
sizeOffsets: offsets
);
}
Widget build(BuildContext context) { Widget build(BuildContext context) {
Color color = backgroundColor; Color color = backgroundColor;
...@@ -83,7 +99,7 @@ class ToolBar extends StatelessComponent { ...@@ -83,7 +99,7 @@ class ToolBar extends StatelessComponent {
), ),
child: new DefaultTextStyle( child: new DefaultTextStyle(
style: sideStyle, style: sideStyle,
child: new IntrinsicHeight(child: new Column(columnChildren)) child: new Container(padding: sizeOffsets, child: new Column(columnChildren, justifyContent: FlexJustifyContent.collapse))
) )
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment