浏览代码

Implement ButtonBar, and Demo

/main
Yuncong Zhang 6 年前
当前提交
d0ebc7bf
共有 2 个文件被更改,包括 91 次插入29 次删除
  1. 53
      Samples/MaterialSample/DividerButtonCanvas.cs
  2. 67
      Runtime/material/button_bar.cs

53
Samples/MaterialSample/DividerButtonCanvas.cs


)
),
new Divider(),
new Container(
width: 100,
height: 50,
child: new FlatButton(
onPressed: () => {
setState(() => {
title = controller.text;
});
},
padding: EdgeInsets.all(5.0),
child: new Center(
child: new Text("Set Title")
new ButtonBar(
children: new List<Widget> {
new FlatButton(
onPressed: () => {
setState(() => {
title = controller.text;
});
},
padding: EdgeInsets.all(5.0),
child: new Center(
child: new Text("Set Title")
)
),
new RaisedButton(
onPressed: () => {
setState(() => {
subtitle = controller.text;
});
},
padding: EdgeInsets.all(5.0),
child: new Center(
child: new Text("Set Subtitle")
)
)
),
new Divider(),
new Container(
width: 100,
height: 50,
child: new RaisedButton(
onPressed: () => {
setState(() => {
subtitle = controller.text;
});
},
padding: EdgeInsets.all(5.0),
child: new Center(
child: new Text("Set Subtitle")
)
)
}
)
}
)

67
Runtime/material/button_bar.cs


using System;
using System.Collections;
using System.Collections.Generic;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
public class ButtonBar : StatelessWidget {
public ButtonBar(
Key key = null,
MainAxisAlignment alignment = MainAxisAlignment.end,
MainAxisSize mainAxisSize = MainAxisSize.max,
List<Widget> children = null
) : base(key : key) {
this.alignment = alignment;
this.mainAxisSize = mainAxisSize;
this.children = children ?? new List<Widget>();
}
public readonly MainAxisAlignment alignment;
public readonly MainAxisSize mainAxisSize;
public readonly List<Widget> children;
public override Widget build(BuildContext context) {
ButtonThemeData buttonTheme = ButtonTheme.of(context);
double paddingUnit = buttonTheme.padding.horizontal / 4.0;
List<Widget> _children = new List<Widget>();
foreach(Widget _child in children) {
_children.Add(new Padding(
padding: EdgeInsets.symmetric(horizontal: paddingUnit),
child: _child
));
}
Widget child = new Row(
mainAxisAlignment: alignment,
mainAxisSize: mainAxisSize,
children: _children
);
switch(buttonTheme.layoutBehavior) {
case ButtonBarLayoutBehavior.padded:
return new Padding(
padding: EdgeInsets.symmetric(
vertical: 2.0 * paddingUnit,
horizontal: paddingUnit
),
child: child
);
case ButtonBarLayoutBehavior.constrained:
return new Container(
padding: EdgeInsets.symmetric(horizontal: paddingUnit),
constraints: new BoxConstraints(minHeight: 52.0),
alignment: Alignment.center,
child: child
);
}
D.assert(false);
return null;
}
}
}
正在加载...
取消
保存