Skip to content

Commit

Permalink
added ToolBar.withSizeOffsets()
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Muller committed Nov 3, 2015
1 parent a127473 commit f072fca
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 27 deletions.
5 changes: 2 additions & 3 deletions examples/widgets/card_collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,14 @@ class CardCollectionState extends State<CardCollection> {
Widget buildToolBar() {
return new ToolBar(
left: new IconButton(icon: "navigation/menu", onPressed: _showDrawer),
center: new Text('Swipe Away'),
right: <Widget>[
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}')
)
)
);
Expand Down
24 changes: 12 additions & 12 deletions sky/packages/sky/lib/src/material/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,18 @@ class DropdownButton<T> extends StatelessComponent {
return new GestureDetector(
child: new Container(
decoration: new BoxDecoration(border: _kDropdownUnderline),
child: new IntrinsicWidth(
child: new Row(<Widget>[
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(<Widget>[
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: () {
Expand Down
20 changes: 10 additions & 10 deletions sky/packages/sky/lib/src/material/scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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(<Widget>[materialBody, toolBar],
if (offsetToolBar != null && materialBody != null)
toolBarAndBody = new CustomMultiChildLayout(<Widget>[materialBody, offsetToolBar],
delegate: _toolBarAndBodyLayout
);
else
toolBarAndBody = toolBar ?? materialBody;
toolBarAndBody = offsetToolBar ?? materialBody;

final List<Widget> bottomColumnChildren = <Widget>[];

Expand Down
20 changes: 18 additions & 2 deletions sky/packages/sky/lib/src/material/tool_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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))
)
);

Expand Down

0 comments on commit f072fca

Please sign in to comment.