[英]Flutter Dropdown Container/Widget
I have spent hours googling something that should be incredibly simple, but have found nothing to this sort on the inte.net.我花了几个小时在谷歌上搜索一些应该非常简单的东西,但在 inte.net 上没有发现任何类似的东西。 Effectively, I want to make a dropdown, so that when a button is clicked, I have a menu dropdown.实际上,我想做一个下拉菜单,这样当点击一个按钮时,我就有一个下拉菜单。 However , I do not wish to have this dropdown be a list of items.但是,我不希望这个下拉列表是一个项目列表。 I want the dropdown to be able to take in a child widget, similar to the showDialog function, and I can pass what I wish to the child widget.我希望下拉列表能够接收子窗口小部件,类似于 showDialog function,我可以将我希望的内容传递给子窗口小部件。
Eg., I wish to merge dropdown's positioning with dialog ability to not only render an opinionated list.例如,我希望将下拉菜单的定位与对话框功能结合起来,而不仅仅是呈现一个自以为是的列表。
Does anyone have any clue how to accomplish this?有谁知道如何做到这一点?
You can use flutter_portal .您可以使用flutter_portal 。 I used this package to build many types of dropdowns.我用这个 package 来构建多种类型的下拉菜单。
Another way I found to do this is to use the showGeneralDialog function and customize the position.我发现的另一种方法是使用 showGeneralDialog function 并自定义 position。
What you could do is to copy the implementation of PopupMenuDivider
:您可以做的是复制PopupMenuDivider
的实现:
class MyEntry extends PopupMenuEntry<Never> {
const MyEntry();
@override
double get height => kMinInteractiveDimension;
@override
bool represents(void value) => false;
@override
State<MyEntry> createState() => _MyEntryState();
}
class _MyEntryState extends State<MyEntry> {
@override
Widget build(BuildContext context) {
return MyWidget();
}
And then you can use it in a PopupMenuButton
:然后你可以在PopupMenuButton
中使用它:
class MyButton extends StatelessWidget {
const MyButton();
@override
Widget build(BuildContext context) {
return PopupMenuButton(
itemBuilder: (context) {
return [
const MyEntry();
];
},
onSeleted: (_) {},
child: MyChild(),
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.