[英]How to make a popup Menu Button like Floating Action Button?
I want to have a Button at the appBar that shows me three further buttons when I click on it like a Floating Action with FAB, but which is positioned at the appBar.我想在 appBar 上有一个按钮,当我点击它时会显示另外三个按钮,就像带有 FAB 的浮动操作一样,但它位于 appBar。
like on the top right corner喜欢在右上角
I tried a lot of options like Floating Action buttons, IconButtons, and PopupMenuButton.我尝试了很多选项,例如浮动操作按钮、图标按钮和弹出菜单按钮。
This is my best solution with a 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(); }),
Is there a more elegant way to make this kind of button, especially solving these two issues with the Backdrop and aligning?有没有更优雅的方法来制作这种按钮,尤其是解决背景和对齐这两个问题?
I would love to hear some advice :)我很想听听一些建议:)
PopupMenuButton
support offset
, you can use offset
to adjust display position PopupMenuButton
支持offset
,可以使用offset
来调整显示位置
You can reference https://medium.com/flutteropen/widgets-14-popupmenubutton-1f1437bbdce2您可以参考https://medium.com/flutteropen/widgets-14-popupmenubutton-1f1437bbdce2
code snippet代码片段
PopupMenuButton<Choice>(
offset: Offset(100, 100),
icon: Icon(
example from reference document参考文档中的示例
Widget _offsetPopup() => PopupMenuButton<int>(
itemBuilder: (context) => [
PopupMenuItem(
value: 1,
child: Text(
"Flutter Open",
style: TextStyle(
color: TEXT_BLACK, fontWeight: FontWeight.w700),
),
),
PopupMenuItem(
value: 2,
child: Text(
"Flutter Tutorial",
style: TextStyle(
color: TEXT_BLACK, fontWeight: FontWeight.w700),
),
),
],
icon: Icon(Icons.library_add),
offset: Offset(0, 100),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.