Flutter 的 ButtonBar widget 可以用來做按鈕的水平排列。

其建構子如下:

ButtonBar({Key key, MainAxisAlignment alignment: MainAxisAlignment.end, MainAxisSize mainAxisSize: MainAxisSize.max, List children: const [] })

屬性如下:

NameTypeDescription
alignmentMainAxisAlignmentHow the children should be placed along the horizontal axis.
childrenListThe buttons to arrange horizontally.
mainAxisSizeMainAxisSizeHow much horizontal space is available. See Row.mainAxisSize.
hashCodeintThe hash code for this object.
keyKeyControls how one widget replaces another widget in the tree.
runtimeTypeTypeA representation of the runtime type of the object.

方法如下:

NameReturn TypeDescription
build(BuildContext context)WidgetDescribes the part of the user interface represented by this widget.
createElement()StatelessElementCreates a StatelessElement to manage this widget’s location in the tree.
debugDescribeChildren()ListReturns a list of DiagnosticsNode objects describing this node’s children.
debugFillProperties(DiagnosticPropertiesBuilder properties)voidAdd additional properties associated with the node.
noSuchMethod(Invocation invocation)dynamicInvoked when a non-existent method or property is accessed.
toDiagnosticsNode({String name, DiagnosticsTreeStyle style })DiagnosticsNodeReturns a debug representation of the object that is used by debugging tools and by toStringDeep.
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug })StringReturns a string representation of this object.
toStringDeep({String prefixLineOne: ‘’, String prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug })StringReturns a string representation of this node and its descendants.
toStringShallow({String joiner: ‘, ‘, DiagnosticLevel minLevel: DiagnosticLevel.debug })StringReturns a one-line detailed description of the object.
toStringShort()StringA short, textual description of this widget.

ButtonBar 使用上要將需要水平排列的按鈕設置在 children 屬性,這些按鈕就會依序的水平排列。

import 'package:flutter/material.dart';

void main() {
runApp(
new MaterialApp(
home:  new ButtonBar(
children: [
new FlatButton(
child: new Text('OK', style: new TextStyle(color: Colors.white)),
onPressed: () {},
color: Colors.blue,
),
new FlatButton(
child: new Text('Cancel', style: new TextStyle(color: Colors.white)),
onPressed: () {},
color: Colors.blue,
),
],
),
)
);
}

1.png

2.png