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


相关推荐
Coffeeee6 小时前
闲聊几句,Android老哥们,你们多久没做技改需求了
android·程序员·代码规范
TT_Close7 小时前
别劝退了!5秒搞定 Flutter 鸿蒙 FVM 起跑线
flutter·harmonyos·visual studio code
萝卜er7 小时前
Fragment 生命周期与状态恢复-《Android深水区(四)》
android
萝卜er7 小时前
Intent 显式、隐式与 PendingIntent-《Android深水区(五)》
android
Kapaseker9 小时前
一文吃透 Kotlin 集合操作符
android·kotlin
三少爷的鞋10 小时前
Main-safe:现代Android 架构真正的分水岭
android
你听得到1110 小时前
用户说 App 卡,但说不清在哪?我把 Flutter 监控 SDK 升级成了链路观测工作台
前端·flutter·性能优化
沐怡旸18 小时前
深入解析 Android Performance Analyzer (APA) 底层架构与技术原理
android
李斯维1 天前
从历史的角度看 Android 软件架构
android·架构·android jetpack
plainGeekDev1 天前
Activity 间传值 → Navigation 参数
android·java·kotlin