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


相关推荐
修炼者16 小时前
【进阶Android】HashMap 的并发“车祸”
android
西西学代码18 小时前
Flutter---回调函数
开发语言·javascript·flutter
冬奇Lab18 小时前
Android 15音频子系统(六):音频焦点管理机制深度解析
android·音视频开发·源码阅读
圣光SG19 小时前
Vue.js 从入门到精通:技术成长之路
flutter
LionelRay20 小时前
Thinking in Compose
android
用户69371750013841 天前
Google 推 AppFunctions:手机上的 AI 终于能自己干活了
android·前端·人工智能
用户69371750013841 天前
AI让编码变简单,真正拉开差距的是UI设计和产品思考
android·前端·人工智能
zh_xuan1 天前
Android Jetpack DataStore存储数据
android·android jetpack·datastore
程序员陆业聪1 天前
在 Android 上跑大模型,你选错引擎了吗?
android
studyForMokey1 天前
【Android面试】View绘制流程专题
android·面试·职场和发展