首页 > 解决方案 > Is there a way to add rounded corners to a DropdownButton menu item list in Flutter?

问题描述

I am trying to add rounded corners to a DropdownButton menu items list. I want to add rounded corners to the actual menu item list, not the DropdownButton.

UI of problem

Is there a way to do this?

标签: flutterdart

解决方案


It doesn't seem to be possible to do that with a DropdownButton, you could achieve that with a PopupMenuButton, like this:

int _selected = 1;

Center(
  child: PopupMenuButton(
    child: Container(
      padding: EdgeInsets.all(8.0),
      color: Colors.lightBlueAccent,
      child: Text('Selected item: $_selected'),
    ),
    onSelected: (value) => setState(() => _selected = value),
    color: Colors.greenAccent,
    shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(Radius.circular(16.0))),
    itemBuilder: (context) {
      return [1, 2, 3]
          .map((value) => PopupMenuItem(
              value: value,
              child: Container(
                child: Text('$value'),
              )))
          .toList();
    },
  ),
)

推荐阅读