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


相关推荐
好的佩奇4 小时前
Dart 之测试
android·flutter·dart
好的佩奇5 小时前
蓝牙之 GATT 数据操作
android·flutter·蓝牙
三少爷的鞋6 小时前
Android 面试系列之-lifecycleScope 和 CoroutineScope(Dispatchers.Main)
android
Mars-xq8 小时前
Android studio下载很慢download fail
android·ide·android studio
2501_915909069 小时前
iOS 上架 App Store 后推送收不到,APNs 证书和生产沙盒环境排查
android·小程序·https·uni-app·iphone·webview
吃不胖爹9 小时前
安卓原生开发的app如何打包成应用
android
ZHOUPUYU11 小时前
PHP 现代工程实践:从语言特性到高性能 Web 应用构建
android·前端·php
treasure14012 小时前
Flutter低级教程(2027年1月重制版)
android·flutter·ios·gui·web·dart·移动端
艾派森13 小时前
Python帕累托分析实战:用二八法则找出贡献80%营收的核心商品
android·开发语言·python
橙光成长14 小时前
GameScrcpy:不装模拟器,用键鼠手柄和 TypeScript 脚本接管你的安卓手游
android·javascript·typescript·开源·1024程序员节