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


相关推荐
吴Wu涛涛涛涛涛Tao1 分钟前
一步到位:用 Very Good CLI × Bloc × go_router 打好 Flutter 工程地基
flutter·ios
九丝城主10 分钟前
2025使用VM虚拟机安装配置Macos苹果系统下Flutter开发环境保姆级教程--中篇
服务器·flutter·macos·vmware
ITfeib22 分钟前
Flutter
开发语言·javascript·flutter
小蜜蜂嗡嗡2 小时前
flutter更改第三方库pub get的缓存目录;更改.gradle文件夹存放目录
flutter
vocal3 小时前
【我的安卓第一课】Android 多线程与异步通信机制(1)
android
顾林海3 小时前
ViewModel 销毁时机详解
android·面试·android jetpack
某非著名程序员4 小时前
Flutter 新手绕不过的坑:ListView 为啥顶部老有空白?
flutter·客户端
恋猫de小郭5 小时前
Google I/O Extended :2025 Flutter 的现状与未来
android·前端·flutter
@Ryan Ding5 小时前
MySQL主从复制与读写分离概述
android·mysql·adb