Flutter:AnimatedPadding动态修改padding
// 默认top为10,点击后修改为100,此时方块会向下移动
padding: EdgeInsets.fromLTRB(left, top, right, bottom),
class _MyHomePageState extends State<MyHomePage> {
bool flag = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('标题'),
),
body: AnimatedPadding(
curve: Curves.easeIn, // 动画属性
duration: Duration(milliseconds: 500),
// 默认
padding: EdgeInsets.fromLTRB(10, flag ?10 : 100, 0, 0),
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
),
floatingActionButton: FloatingActionButton(
onPressed: (){
flag = !flag;
setState(() {});
},
child: const Icon(Icons.add),
),
);
}
}