【发布时间】:2020-08-28 13:29:50
【问题描述】:
我想知道如何更改popUpMenu 的原点,在底部应用栏上方启动弹出窗口,无论项目数量如何。与屏幕的右端对齐。类似的东西(例如)
Positioned(right: 0, bottom: bottomAppBarHeight)
下面是我想要实现的popUpMenu的设计布局截图:
这是popUpMenu当前位置的截图(请忽略其他设计差异,因为它们无关紧要):
使用的代码如下:
onPressed: () {
final RelativeRect position =
buttonMenuPosition(context);
showMenu(context: context, position: position, items: [
PopupMenuItem<int>(
value: 0,
child: Text('Working a lot harder'),
),
PopupMenuItem<int>(
value: 1,
child: Text('Working a lot less'),
),
PopupMenuItem<int>(
value: 1,
child: Text('Working a lot smarter'),
),
]);
},
buttonMenuPosition功能码:
RelativeRect buttonMenuPosition(BuildContext context) {
final bool isEnglish =
LocalizedApp.of(context).delegate.currentLocale.languageCode == 'en';
final RenderBox bar = context.findRenderObject() as RenderBox;
final RenderBox overlay =
Overlay.of(context).context.findRenderObject() as RenderBox;
const Offset offset = Offset.zero;
final RelativeRect position = RelativeRect.fromRect(
Rect.fromPoints(
bar.localToGlobal(
isEnglish
? bar.size.centerRight(offset)
: bar.size.centerLeft(offset),
ancestor: overlay),
bar.localToGlobal(
isEnglish
? bar.size.centerRight(offset)
: bar.size.centerLeft(offset),
ancestor: overlay),
),
offset & overlay.size,
);
return position;
}
更改偏移无效。
【问题讨论】:
-
你能解释一下你想在哪个顺序显示弹出窗口吗?除了你的用户界面上显示的内容。
-
我想在底部应用栏上方启动弹出窗口,无论项目数量如何。与屏幕的右端对齐。类似于(例如)
Positioned(right: 0, bottom: bottomAppBarHeight)的东西 -
这不适用于弹出窗口,您必须为其设计自定义小部件
-
你能给我看一个带代码的例子吗?答案当然不是评论。
-
所以你想在点击更多选项时打开这个?