繁体   English   中英

Flutter 下拉菜单在屏幕中间居中并且只显示几个项目?

[英]Flutter Dropdown to be centered in the middle of screen and only show a few items?

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

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

太感谢了!

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,
 ),

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM