我试图创建一个向上展开的下拉菜单,但我无法更改方向,我认为问题可能是AnimatedContainer高度,但我不知道如何解决它.此外,我希望它是四舍五入的,我try 添加ClipRect和BorderRadius.这是我的代码:
class HomeDropdownMenu extends StatefulWidget {
const HomeDropdownMenu({Key? key}) : super(key: key);
@override
_HomeDropdownMenuState createState() => _HomeDropdownMenuState();
}
class _HomeDropdownMenuState extends State<HomeDropdownMenu> {
bool _isExpanded = false;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
GestureDetector(
onTap: () {
setState(() {
_isExpanded = !_isExpanded;
});
},
child: Container(
color: Colors.blue,
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Center(
child: Text(
'Menu',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
Icon(
_isExpanded ? Icons.expand_more_rounded : Icons.expand_less_rounded,
size: 30,
),
],
),
),
),
Transform(
transform: Matrix4.translationValues(0.0, _isExpanded ? -20.0 : 0.0, 0.0) ,
child: ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
height: _isExpanded ? min(MediaQuery.of(context).size.height * 0.5, MediaQuery.of(context).size.height - 80) : 0,
width: double.infinity,
color: Colors.white,
child: SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: Column(
children: [
MenuOptions();
],
),
),
),
),
),
],
);
}