From f072fca3bc7457836cfb04d31c3b473535dc6b8b Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 3 Nov 2015 14:03:31 -0800 Subject: [PATCH] added ToolBar.withSizeOffsets() --- examples/widgets/card_collection.dart | 5 ++-- .../sky/lib/src/material/dropdown.dart | 24 +++++++++---------- .../sky/lib/src/material/scaffold.dart | 20 ++++++++-------- .../sky/lib/src/material/tool_bar.dart | 20 ++++++++++++++-- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/examples/widgets/card_collection.dart b/examples/widgets/card_collection.dart index b96e59670ed1d..8142b16b35aa8 100644 --- a/examples/widgets/card_collection.dart +++ b/examples/widgets/card_collection.dart @@ -268,15 +268,14 @@ class CardCollectionState extends State { Widget buildToolBar() { return new ToolBar( left: new IconButton(icon: "navigation/menu", onPressed: _showDrawer), - center: new Text('Swipe Away'), right: [ new Text(_dismissDirectionText(_dismissDirection)) ], bottom: new Padding( - padding: const EdgeDims.only(left: 32.0), + padding: const EdgeDims.only(left: 72.0), child: new Align( alignment: const FractionalOffset(0.0, 0.5), - child: new Text("Remaining items: ${_cardModels.length}") + child: new Text('Swipe Away: ${_cardModels.length}') ) ) ); diff --git a/sky/packages/sky/lib/src/material/dropdown.dart b/sky/packages/sky/lib/src/material/dropdown.dart index 4905a505f60ed..15bc2ca31a149 100644 --- a/sky/packages/sky/lib/src/material/dropdown.dart +++ b/sky/packages/sky/lib/src/material/dropdown.dart @@ -218,18 +218,18 @@ class DropdownButton extends StatelessComponent { return new GestureDetector( child: new Container( decoration: new BoxDecoration(border: _kDropdownUnderline), - child: new IntrinsicWidth( - child: new Row([ - new IndexedStack(items, - key: indexedStackKey, - index: selectedIndex, - alignment: const FractionalOffset(0.5, 0.0) - ), - new Container( - child: new Icon(icon: 'navigation/arrow_drop_down', size: IconSize.s36), - padding: const EdgeDims.only(top: 6.0) - ) - ]) + child: new Row([ + new IndexedStack(items, + key: indexedStackKey, + index: selectedIndex, + alignment: const FractionalOffset(0.5, 0.0) + ), + new Container( + child: new Icon(icon: 'navigation/arrow_drop_down', size: IconSize.s36), + padding: const EdgeDims.only(top: 6.0) + ) + ], + justifyContent: FlexJustifyContent.collapse ) ), onTap: () { diff --git a/sky/packages/sky/lib/src/material/scaffold.dart b/sky/packages/sky/lib/src/material/scaffold.dart index c189d6868842e..c41696a1ad36a 100644 --- a/sky/packages/sky/lib/src/material/scaffold.dart +++ b/sky/packages/sky/lib/src/material/scaffold.dart @@ -10,8 +10,8 @@ import 'package:flutter/widgets.dart'; import 'constants.dart'; import 'material.dart'; -const int _kToolBarIndex = 1; const int _kBodyIndex = 0; +const int _kToolBarIndex = 1; // 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 @@ -22,18 +22,17 @@ class _ToolBarAndBodyLayout extends MultiChildLayoutDelegate { assert(childCount == 2); final BoxConstraints toolBarConstraints = constraints.loosen().tightenWidth(size.width); final Size toolBarSize = layoutChild(_kToolBarIndex, toolBarConstraints); - final double topPadding = ui.window.padding.top; - final double bodyHeight = size.height - toolBarSize.height - topPadding; + final double bodyHeight = size.height - toolBarSize.height; final BoxConstraints bodyConstraints = toolBarConstraints.tightenHeight(bodyHeight); layoutChild(_kBodyIndex, bodyConstraints); - positionChild(_kToolBarIndex, new Point(0.0, topPadding)); - positionChild(_kBodyIndex, new Point(0.0, topPadding + toolBarSize.height)); + positionChild(_kToolBarIndex, Point.origin); + 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({ Key key, this.body, @@ -48,14 +47,15 @@ class Scaffold extends StatelessComponent { final Widget floatingActionButton; 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; Widget toolBarAndBody; - if (toolBar != null && materialBody != null) - toolBarAndBody = new CustomMultiChildLayout([materialBody, toolBar], + if (offsetToolBar != null && materialBody != null) + toolBarAndBody = new CustomMultiChildLayout([materialBody, offsetToolBar], delegate: _toolBarAndBodyLayout ); else - toolBarAndBody = toolBar ?? materialBody; + toolBarAndBody = offsetToolBar ?? materialBody; final List bottomColumnChildren = []; diff --git a/sky/packages/sky/lib/src/material/tool_bar.dart b/sky/packages/sky/lib/src/material/tool_bar.dart index 96f097cc50834..666804ae802f6 100644 --- a/sky/packages/sky/lib/src/material/tool_bar.dart +++ b/sky/packages/sky/lib/src/material/tool_bar.dart @@ -20,7 +20,8 @@ class ToolBar extends StatelessComponent { this.bottom, this.level: 2, this.backgroundColor, - this.textTheme + this.textTheme, + this.sizeOffsets: EdgeDims.zero }) : super(key: key); final Widget left; @@ -30,6 +31,21 @@ class ToolBar extends StatelessComponent { final int level; final Color backgroundColor; 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) { Color color = backgroundColor; @@ -83,7 +99,7 @@ class ToolBar extends StatelessComponent { ), child: new DefaultTextStyle( style: sideStyle, - child: new IntrinsicHeight(child: new Column(columnChildren)) + child: new Container(padding: sizeOffsets, child: new Column(columnChildren, justifyContent: FlexJustifyContent.collapse)) ) );