首页 > 解决方案 > Flutter Dropdown 在屏幕中间居中并且只显示几个项目?

问题描述

目前我正在尝试创建一个位于屏幕右侧的下拉菜单,当您单击它以选择权重时,它将在屏幕中间弹出并仅显示一些权重,其余的它被填充包围,就像这张图片:(就像这张图片

这就是我在代码中的样子。

太感谢了!

class Weight {
int amount;

Weight(this.amount);

static List<Weight> getWeight() {
return <Weight>[
  Weight(66),
  Weight(67),
  Weight(68),
  Weight(69),
  Weight(70),
  Weight(71),
  Weight(72),
  Weight(73),
  Weight(74),
  Weight(75),
  Weight(76),
];
}

static List<DropdownMenuItem<Weight>> buildDropdownMenuItemsWeight(
  List weightAmount) {
List<DropdownMenuItem<Weight>> items = List();


for (Weight weight in weightAmount) {
  items.add(DropdownMenuItem(
    value: weight,
    child: Text('${weight.amount} Lbs'),
  ));
}
return items;
}


 // Bottom that I'm using on the other page, to reference the above class to display the items in dropdown.
 DropdownButton(
      value: _selectedWeightSystem,
      items: _dropdownMenuItems,
      onChanged: onChangeDropdownItemWeightSystem,
 ),

标签: flutterflutter-layoutflutter-dependencies

解决方案


它已经有了解决您问题的软件包。使用这个数字选择器。它还支持 UI 作为您给出的示例


推荐阅读