Flutter:AnimatedPadding动态修改padding

时间:2024-11-21 13:06:10
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), ), ); } }