Home > Software design >  Flutter Dropdown Container/Widget
Flutter Dropdown Container/Widget

Time:03-09

I have spent hours googling something that should be incredibly simple, but have found nothing to this sort on the internet. 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?

CodePudding user response:

You can use flutter_portal. I used this package to build many types of dropdowns. enter image description here

CodePudding user response:

Another way I found to do this is to use the showGeneralDialog function and customize the position.

CodePudding user response:

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(),
    );
  }
}
  • Related