How can we change the width/padding of a Flutter DropdownMenuItem in a Dropdown?

前端 未结 3 518
天命终不由人
天命终不由人 2021-02-12 14:45

In Flutter, I can build a Dropdown with DropdownMenuItems, like this:

The DropdownMenuItems I add are always wider than the dropdown itself:

How do you

3条回答
  •  别跟我提以往
    2021-02-12 15:14

    This feature has been added. See https://github.com/flutter/flutter/pull/14849

    You can now wrap it in a ButtonTheme and set alignedDropdown to true.

    return Container(
        width: 300.0,
        child: DropdownButtonHideUnderline(
          child: ButtonTheme(
            alignedDropdown: true,
              child: DropdownButton(
                value: name,
                items: listOfDropdownMenuItems,
                onChanged: onChanged,
                style: Theme.of(context).textTheme.title,
             ),
          ),
        ),
    );
    

提交回复
热议问题