【发布时间】:2020-05-27 10:05:21
【问题描述】:
我想在 appBar 上有一个 Button,当我点击它时,它会向我显示三个其他按钮,就像 FAB 的浮动操作一样,但它位于 appBar 上。
喜欢右上角
我尝试了很多选项,例如浮动操作按钮、图标按钮和 PopupMenuButton。
这是我使用 PopupMenuButton 的最佳解决方案:
PopupMenuButton<Choice>(
icon: Icon(
MyIcon.edit,
size: 35, color: Colors.white,
),
// child: IconButton( icon: Icon(
// MyIcon.edit,
// // color: Colors.white,
// size: 35, color: Colors.white,
// ),onPressed: _buildLayoutContainer,
// ),
elevation: 0,
onSelected: choiceAction,
itemBuilder: (BuildContext context) {
return choices.map((Choice choice) {
if (choice.text == null) {
return PopupMenuItem<Choice>(
value: choice,
child: Row(
children: <Widget>[
SizedBox(
height: 50,
width: 1,
),
],
),
);
} else {
return PopupMenuItem<Choice>(
value: choice,
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
SizedBox(
width: 103,
),
choice.text,
SizedBox(
width: choice.width,
),
Column(
children: <Widget>[
IconButton(
icon: choice.icon,
onPressed: () => _selectTransaction(context),
),
SizedBox(
height: choice.height,
)
],
),
],
),
);
}
}).toList();
}),
有没有更优雅的方法来制作这种按钮,特别是解决背景和对齐这两个问题?
我很想听听一些建议:)
【问题讨论】:
-
是否可以更改位置 itembuilder 卡来解决对齐问题?