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


相关推荐
sTone873751 小时前
写时复制COW的第一性理解
android·c++·flutter
sTone873751 小时前
Zygote的第一性理解
android
sTone873751 小时前
类RN框架通过Service暴露卡片渲染能力给AI Chat
android·react native
灯火不休1 小时前
Android Studio & Flutter 构建命令完全指南
android
杉氧1 小时前
Ktor 全栈之路 (5):JWT 认证全流程实战 —— 打造安全通信闭环
android·架构·kotlin
nicepainkiller1 小时前
codex 逆向 flutter
flutter·flutter 逆向
️学习的小王1 小时前
Python + MySQL 学生信息管理系统实战教程
android·python·mysql
帅次1 小时前
Android 高级工程师面试:Flutter 路由导航 近1年高频追问 18 题
android·flutter·面试
浮江雾2 小时前
Flutter第七节-----快捷键创建组件与flutter中的点击事件
flutter
alexhilton10 小时前
MVI模式的完整历史、误解和现代Android范式
android·kotlin·android jetpack