我正在拼命寻找一种方法将项目放置在按钮下方。
正如您所看到的,如果先前选择了第一项,则列表顶部与按钮处于同一级别。
但是,如果我之前选择了最后一项,则下拉列表的位置使列表在按钮级别结束。
这不是我想要的行为。我希望它始终位于第一个屏幕截图中,即使之前选择的不是第一个元素。
class DropDownButton extends StatefulWidget {
final List<String> options;
const DropDownButton({Key? key, required this.options}) : super(key: key);
@override
State<DropDownButton> createState() => _DropDownButtonState();
}
class _DropDownButtonState extends State<DropDownButton> {
String dropdownValue = '';
@override
Widget build(BuildContext context) {
dropdownValue = dropdownValue.isEmpty ? widget.options[0] : dropdownValue;
return SizedBox(
height: 70,
child: Container(
margin: const EdgeInsets.fromLTRB(2, 5, 2, 5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(3),
border: Border.all(color: Colors.white, width: 2),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
isExpanded: true,
value: dropdownValue,
items: widget.options
.map((e) =>
DropdownMenuItem(
value: e,
child: Text(e)))
.toList(),
onChanged: (value) {
setState(() {
dropdownValue = value!;
});
}),
),
),
);
}
}
既然我正在谈论这个话题。有没有办法做到这一点,使列表实际上位于按钮下方,并且您实际上可以看到带有提示文本的按钮?
Like
-Button-
-item1-
-item2-
-item3-