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),
      ),
    );
  }
}


相关推荐
louisgeek11 小时前
Android Studio 和 Git
android
程序员老刘14 小时前
腾讯混元Hy3在Flutter项目中的实战体验
flutter·ai编程
ailinghao15 小时前
flutter常用的内置特性
flutter
solo_9915 小时前
Android Event 日志完全指南
android
孙晓鹏life16 小时前
MySQL-Seconds_behind_master的精度误差
android·mysql·adb
雨白16 小时前
C 语言文件操作核心
android
子非鱼942718 小时前
10-Flutter调用鸿蒙原生能力前置课:MethodChannel和PlatformView准备
学习·flutter·华为·harmonyos
鱼儿也有烦恼18 小时前
01.搭建Android Studio开发环境
android·android studio
xd18557855518 小时前
鸿蒙PC时代的AI快递查询应用:基于鸿蒙Flutter框架的跨端创新实践
人工智能·flutter·华为·harmonyos·鸿蒙
m0_7381207218 小时前
PHP代码审计基础——面向对象(四)
android·开发语言·网络·安全·github·php