I have spent hours googling something that should be incredibly simple, but have found nothing to this sort on the 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.
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 . I used this package to build many types of dropdowns.
Another way I found to do this is to use the showGeneralDialog function and customize the position.
What you could do is to copy the implementation of 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
:
class MyButton extends StatelessWidget {
const MyButton();
@override
Widget build(BuildContext context) {
return PopupMenuButton(
itemBuilder: (context) {
return [
const MyEntry();
];
},
onSeleted: (_) {},
child: MyChild(),
);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.