【发布时间】:2020-12-05 09:16:45
【问题描述】:
我正在尝试在 Flutter 中创建一个自定义下拉菜单,它只是一个简单的按钮,点击时会显示可滚动的产品行。我附上了一些图像,可以更好地显示我所指的内容。我尝试使用 IconButton 和 AnimatedContainer 但我似乎无法让它工作。我希望有人对如何做这样的事情有更好的想法。
顺便说一下,这是我的代码:
class ModelsDropdown extends StatefulWidget {
final List<Phone> phones;
ModelsDropdown({@required this.phones});
@override
_ModelsDropdownState createState() => _ModelsDropdownState();
}
class _ModelsDropdownState extends State<ModelsDropdown> {
bool _droppedDown;
@override
void initState() {
_droppedDown = false;
super.initState();
}
@override
Widget build(BuildContext context) {
return AnimatedContainer(
duration: Duration(milliseconds: 300),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100.0),
border: Border.all(width: 2.0)
),
width: 32.0,
height: 32.0,
child: Column(
children: [
IconButton(
padding: const EdgeInsets.only(right: 0.0),
icon: Icon(
_droppedDown ? Icons.expand_more : Icons.expand_less
),
color: Colors.black,
onPressed: () {
setState(() {
_droppedDown = !_droppedDown;
});
}
),
_droppedDown ?
Container(
width: MediaQuery.of(context).size.width,
height: 300.0,
color: Colors.orangeAccent,
) :
SizedBox.shrink()
],
),
);
}
}
容器在底部,它甚至不起作用。我收到溢出错误。很感谢任何形式的帮助。非常感谢大家。
【问题讨论】:
-
将 iconButton 包裹在扩展的小部件中
标签: flutter dart mobile flutter-layout flutter-animation