Flutter:AnimatedPadding动态修改padding

html 复制代码
// 默认top为10,点击后修改为100,此时方块会向下移动
padding: EdgeInsets.fromLTRB(left, top, right, bottom),
js 复制代码
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),
      ),
    );
  }
}


相关推荐
霸王大陆13 分钟前
《零基础学 PHP:从入门到实战》教程-模块四:数组与函数-2
android·开发语言·php
v***431723 分钟前
springboot3整合knife4j详细版,包会!(不带swagger2玩)
android·前端·后端
h***047738 分钟前
MySQL 的 INSERT(插入数据)详解
android·数据库·mysql
w***42442 分钟前
SpringSecurity的配置
android·前端·后端
s***35301 小时前
SpringMVC新版本踩坑[已解决]
android·前端·后端
不会写代码的猴子1 小时前
Android16重磅更新:安全与性能全面升级
android
霸王大陆1 小时前
《零基础学 PHP:从入门到实战》教程-模块四:数组与函数-1
android·开发语言·php
e***19352 小时前
MySQL-触发器(TRIGGER)
android·数据库·mysql
不会写代码的猴子2 小时前
Android16
android